I'm trying to clean up my objects after I get done with them. During a session on my tomcat server, serveral arraylists are built for the end user-at the end of the session, I want to clear out the arraylists so that they can be ready for garbage collection-and to free up memory. I'm not sure if the arraylists' clear or removeall methods will do the trick.
Hi Matthew As the previous answer says, if there are no other active references to the ArrayList in question, set its reference to null and it will become eligible for garbage collection. However, I get the feeling that you wish to clean up all the objects contained within the ArrayList. In order to make these objects eligible for garbage collection, you need to ensure that there are no other active references to them in other parts of the program. If there are, simply calling <code>clear()</code> on the ArrayList and then setting it to null will NOT result in the objects it contained becoming eligible for garbage collection. Although the memory used by the ArrayList object may be reclaimed, the memory used by the objects that the ArrayList contained will still be in use. So be careful. Hope this helps Michael
------------------ "One good thing about music - when it hits, you feel no pain" Bob Marley
"One good thing about music - when it hits, you feel no pain" <P>Bob Marley
Matthew X. Brown
Joined: Nov 08, 2000
What is the definition of an "active" reference by the java virtual machine?
Joined: Aug 22, 2001
By 'active reference' I mean a reference from an object that is not itself eligible for garbage collection, i.e. if 2 objects hold references to each other in a situation known as a 'circular reference' in C++, those objects will still be eligible for garbage collection in Java as long as there are no other references to them. So, a reference to an object from another object that is itself eligible for garbage collection is not considered to be an 'active' reference, and will not prevent garbage collection. ------------------ "One good thing about music - when it hits, you feel no pain" Bob Marley