开发者

java memory pressure

开发者 https://www.devze.com 2023-04-03 03:19 出处:网络
Are there features in Java to tell 开发者_如何学JAVAthe runtime about unmanaged memory allocation like the GC.AddMemoryPressure method in .NET?I guess this is not required in Java. \'If a small manage

Are there features in Java to tell 开发者_如何学JAVAthe runtime about unmanaged memory allocation like the GC.AddMemoryPressure method in .NET?


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 memory Management for JNI


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

ByteBuffer bb = ByteBuffer.allocateDirect(1024*1024);

((DirectBuffer) bb).cleaner().clean();

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号