You have to separate two things:
- memory usage inside the vm
this is what you see if you print out:
Runtime.getRuntime().totalMemory()
Runtime.getRuntime().freeMemory()
You have hardly any control about the
execution of the garbage collector. The
only contract that you can take for granted,
is that any JVM will do the garbage collection,
if it runs out of memory. All other things
(calling system.gc(), terminating a method,
setting all references to an object to null) are
just hints for the JVM that can be ignored.
From the java doc of System.gc():
Calling the gc method >suggests< that the Java
Virtual Machine expend effort toward recycling
unused object
- memory usage of the vm
this is what you see with top/ps/task manager
Even if all objects are garbage collected, that doesn't
mean that the size of the JVM shrinks, it is possible
that only the free memory inside the JVM grows for each
byte that is garbage collected. Wether the JVM is able to
decrease it's memory footprint is up to the JVM and the
underlying operating system.
> -----Urspr�ngliche Nachricht-----
> Von: Wolle [mailto:[EMAIL PROTECTED]]
> Gesendet: Montag, 7. Mai 2001 03:46
> An: tomcatUser
> Betreff: My growing memory problem resolved
>
>
> Hello ,
> i have posted for a few day's a problem thats the Memory usage will
> extremly grow up when I refresh a page very often
> The Problem was, that I creat a "heavy memory" Object on each refresh.
> Normally I have 81 processes run at all, when execute the
> "stress-test"
> the processcount will rise till ~ 230. And each new Prcoesses
> will creat
> a new Object.
> When I stop the stress-test, the processcount becomes normal (~ 100) ,
> but the memory usage won't fall.
> But the new created Object have now refernces that points to them.
> But why they don't becomes free ???? My code is somthing like this:
>
> public class servlet1 extends HttpServlet{
> ..
> ...
> ..
> ..
> public void doPost(HttpServletRequest request,HttpServletResponse
> response)
> throws IOException{
> try{
> HeavyObject ho = new HeavyObject();
> }
> finally{
> ho = null; // for testing implementet, but this gives the
> memory not free, also
> }
>
> }
> }
>
> Is this a Bug in Tomcat ? Or is it a Bug from me ? Or som Java
> misunderstood ?
> Why will the Object not becomes free, when some of the Threads will be
> closed ,
> and the only reference is in the closed Thread ?
>
>
> Greetings,
> Michael
>
>