Rajesh.Rapaka said:
Hi,
Thank you for all the answers gentlemen. But isn't there a way by which
I can free the used memory as soon as I close the window, without
acessing the VM. I believe java should actually be releasing the memory
it allocated for the diplaying the Internal Frame as soon as it is
disposed.
I somehow don't get the idea of expanding the heap or manipulating the
VM appealing. Because any program written is ment to be installed on
several machines which have various memory sizes and various virtual
machines. So I dont get the idea appealing. (plz correct if my attitued
is wrong).
You aren't "wrong," but the set of programs that would
benefit from returning memory to the O/S is smaller than
one might expect. Consider:
1: At some point in its execution, the program must
acquire a large amount of memory (otherwise, it can
only return a small amount, and this isn't a large
benefit).
2: Having acquired a large amount of memory, the program
must enter a phase where it needs far less (otherwise,
it could only return a small amount).
3: After returning the unneeded memory, the program must
continue to run for a long time (returning a gigabyte
one millisecond before termination doesn't help much).
4: There should not be another "mountain" on the other
side of the memory "valley" (otherwise the program
would need to request memory from the O/S a second
time, and re-requesting the memory would certainly
take longer than simply re-using memory that has
been hanging around).
So: The overall picture is that of a program that runs
in "phases," where the early phases require a lot of memory
and the later phases (which run for a long time) require very
little. One can imagine such programs, but they're fairly
unusual -- and some of the counter-examples might profitably
be broken into two or more programs anyhow.
Of course, there are exceptions. One can imagine a long-
running program that alternates between periods of heavy memory
use and lengthy periods of light use -- maybe it does very
little most of the time, but every hour on the hour it wakes
up and rummages through a twenty-terabyte database before going
dormant again. The system as a whole might benefit from being
able to reclaim this program's memory for fifty minutes out of
each hour. Also, one can take issue with point 4 above: if
you've got a gigabyte of useless memory pages sitting on the
swap device, it may well be cheaper to tell the O/S you don't
want them any more and then ask for new pages than to fault in
the old ones merely to overwrite their useless contents. Still
and all, the "obvious" benefits of returning memory to the O/S
usually turn out to be smaller than is "obviously" the case.
(By the way, the above is not merely airy theorizing.
At a PPOE I was coerced into writing a memory manager that
returned unused pages to the O/S, so our memory-hungry program
wouldn't look quite so piggy. Result: The program slowed down
noticeably, and the actual memory usage really didn't decrease
very much. I'm not making generalizations based on thin air;
my claims are based on a statistically significant sample of
size N=1 ;-)