• Post Reply Bookmark Topic Watch Topic
  • New Topic

Deallocate Memory Problem

 
mickey scott
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello to everybody,I have a memoy problem.
I create an Instance of a class which reads from an xml and populates a DefaultMutableTreeNode.In the main class I retrieve the DefaultMutableTreeNode and clear all its childs and put to null him and the son class and also call the System.gc() method,but the memory allocated by the parse process persist? Why? How can I DEALLOCATE the memory allocated creating an Object that is not more necessary?
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Calling System.gc() doesn't guarantee memory will be freed immediately. You should rarely need to worry about when the JVM releases memory.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
memory allocated by the parse process persist?

How are you determining this? using the Runtime methods from inside the JVM or Operating system methods from outside?
Bill
 
mickey scott
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see this by the Window Task Manager tool....
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

First, a bit of business: you may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. Cute nicknames and "handles" aren't acceptable on this site. You can change your display name
here.
Thanks!

Now, on to your question: java.exe never releases memory to the OS. The Java heap can grow up to a predetermined maximum size, but doesn't shrink (until java.exe exits, of course.) When objects are freed, the memory goes back into the free list in the Java heap, to be reused for other Java objects.
 
mickey scott
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok,but how can I force the object freeding?It doesn't seem to work also if I call the System.gc()...there is some other way to do it?
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What EFH said is that watching the memory usage through the Windows Task Manager is worthless and does NOT let you know if the object has been freed or not. It is quite possible that the object has been gc'd, but this will not show up in windows as the JVM will reserve that memory to be used when you create new Java objects.

There are runtime methods that can tell you how much free and used space is on the heap at any given time. This would give you an idea as to the state of the memory usage within your app.

That said there is no way to force the JVM to run gc or to free memory. The JVM will ensure there is enough memory for your program to run provided you do not allocate more objects than memory available. It is garunteed that objects will be gc'd before you reach an OutOfMemory state.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Ernest tried to explain, most likely the objects actually *are* garbage collected. You can't see this using the task manager, because garbage collection does release the memory to the java heap, not to windows. If you don't get an OutOfMemoryError, you are probably save.

Anyway, *please* adjust your display name, as request by Ernest above. Thanks!
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're in JDK 5 try watching your program with JConsole
 
Sumit Deshpande
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

You can check the details about the garbage collection using -verbose:gc option with your java.exe. It prints information at every collection as shown below
[GC 325407K->83000K(776768K), 0.2300771 secs]
The numbers before and after the arrow represent the size of live objects before and after garbage collection and the number in parenthesis is total available space.

Regards,
Sumit.
[ April 25, 2005: Message edited by: Sumit Deshpande ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!