As far as I know, for space in old generation of JVM, it could be utilized for two purposes,
- used for objects promoted from young generation to old generation?
- used for new object allocation in special use cases (https://stackoverflow.com/questions/9053144/will-i-encounter-java-lang-outofmemoryerror-even-with-no-lack-of-memory)
My questions are,
- Are there any other use cases to which will utilize space in old generation?
- I think there is a memory copy involved to copy objects from young generation to old generation, is it a deep copy or a shallow copy?
thanks in advance, Lin
Placing this code in response to the question by @Lin Ma in his comment:
UDPATE
How to solve this leak
Only way to solve the leak it to Profile the application using some profiling tools such as JProfiler, VisualVM and find out which class is causing the leak.
When you find the class, THE CODE WILL HAVE TO BE CHANGED and that is the only way.
There is no need to free the references before the program exiting. Reason is that
static
variables (memoryLeakCulprit
) are bound to Class object, and as soon as you exit the program all the references are automatically freed including the Class Object.On totally other note always make sure to close System Resources (Sockets, DB connections) before exiting the program.
Let me answer 2. It is definitely not a deep copy: the GC handles objects as distinct memory blocks and deep copying really only means copying many distinct objects that are connected into an object graph. Also, you'd be better served by imagining a move, not a copy; copying is in fact just an "implementation detail" and the desired effect is relocating.