Are there features in Java to tell the runtime about unmanaged memory allocation like the GC.AddMemoryPressure method in .NET?
-
2What's this stuff about "quality standards"?Alexander Rühl– Alexander Rühl2011年09月06日 12:45:20 +00:00Commented Sep 6, 2011 at 12:45
-
That is a place holder text to pass stackoverflow quality standards checker.michael nesterenko– michael nesterenko2011年09月06日 12:48:35 +00:00Commented Sep 6, 2011 at 12:48
-
@misha nesterernko Place holder text? If it's not part of the question then it has no need to be there.Michael Berry– Michael Berry2011年09月06日 12:49:47 +00:00Commented Sep 6, 2011 at 12:49
2 Answers 2
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:
3 Comments
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)
2 Comments
Explore related questions
See similar questions with these tags.