Re: Remove JFrame from memory
On 6/28/2012 9:48 AM, Jesper Johnsen wrote:
How do I remove an object lets say a JFrame from memory? I know that
the garbage collector handles this - but this simple example does not
release itself... java.exe uses 10mb in the first wait stage, this
increases to 20mb when the JFrame is shown, but the memory usage
never returns to the initial 10mb.
I take it you found this by looking at memory usage in the Task Manager.
For programs that do a lot of custom memory management, a category which
Java falls into, what Task Manager reports is fairly useless.
For various reasons, the "memory" that Java uses can be divided into
several classes:
VM - the amount of virtual memory that the OS has given to Java
committed - the amount of virtual memory that is backable by physical memory
allocated - the amount of virtual memory that is actually used by some
objects in memory.
The number you see in the task manager is most closely correlated to the
first metric (more specifically, it's the amount of memory which isn't
accessible to any other processes). To see the other values, you need to
use Java's internal memory management APIs.
IIRC, Java does what amounts to lazy initialization of the AWT, which
you probably can't uninitialize, so some of the memory usage you see may
be related to the AWT initialization.
In short: you have numbers which are useless and say pretty much nothing.
--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth