java告诉JVM使用了多少本机内存
我的问题与Java-Native-Code-Background密切相关:
You cannot control native memory from Java really well. You might have heard about native buffers, but what they haven’t told you is that Java doesn’t properly garbage native buffers. The problem is that Java doesn’t take the size of the native buffers into account, meaning that it will at some point free a native buffer, but if you have really many of those, then it probably won’t be before you run out of memory. This means that all data has to be stored in Java objects.
因此,为了告诉JVM它应该运行GC,是否可能以某种方式告知或注册使用的本机内存量? 如果我理解正确,那么Dalvik does this,但是在所有JVM上都有一个可靠的方法这样做会很好
谢谢
# 1 楼答案
你无法告诉JVM使用了多少本机内存,JVM根本没有任何接口。但如果你只是不想因为JVM没有注意到你使用了多少内存而耗尽内存,我可以想出两种方法: