java内存压力
Java 中是否有功能可以告诉运行时有关非托管内存分配的信息,例如 .NET 中的 GC.AddMemoryPressure 方法?
Are there features in Java to tell the runtime about unmanaged memory allocation like the GC.AddMemoryPressure method in .NET?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想这在Java中不是必需的。 “如果一个小的托管对象分配大量非托管内存”在 Java 中根本不会发生,如果您通过 JNI 调用本机(非托管)函数,则内存不会分配给 JVM 的托管内存表。
供参考:
I guess this is not required in Java. 'If a small managed object allocates a large amount of unmanaged memory' can simply not happen in Java, if you call native (unmanaged) functions via JNI the memory is not assigned to the JVM's managed memory table.
For reference:
直接内存在 Java 中是单独管理的,可以被视为“非托管”。在Sun/Oracle JVM中,它有自己的内存使用限制,您可以立即达到堆大小和直接内存大小的限制。
在 Sun/Oracle JVM 中,您可以使用内部 API 显式释放直接内存块。您很少需要这样做,但这里介绍了如何
在不触发 GC 的情况下执行一万次。
顺便说一句:内存映射文件使用少量堆,不计入直接内存限制。您可以映射的数量实际上是无限的。 (虽然一个 MappedByteBuffer 限制为 2GB)
The direct memory is managed separately in Java and could be considered "unmanaged". In the Sun/Oracle JVM it has its own memory usage limit and you can reach the limit of the heap size and the direct memory size at once.
In the Sun/Oracle JVM you can explicitly free a direct memory block using an internal API. It is rare you should even need to do so but here is how
You can do this a ten thousand times without triggering a GC.
BTW: Memory mapped files use a small amount of heap and doesn't count to the direct memory limit. The amount you can map in is practically unlimited. (Though limited to 2GB in one MappedByteBuffer)