Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stack memory vs. Heap memory (garbage collection)

Status
Not open for further replies.

vulcand4

Programmer
Jul 29, 2003
76
US
Question:

The garbage collector is designed to clean up unreferenced Heap storage. Does the memory stack (used by executing methods) get cleaned up periodically also, or does it get cleaned up immediately upon method termination?
 
garbage collector runs when there is too much garbage on the memory. You can run it when you want by calling System.gc()

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
the call on GC only asks GC to run.. it's not sure that the GC will run.. you can't force GC to run... You can point that object is ready for garbage by putting object = null.. the call of system.gc() just tells the GC to run... but that can be now or in the next 10 minutes
 
Usually the stack will be cleaned on method termination, but if some objects were created they are likely to be in the heap not the stack. The stack is usually used to store small things like parameter references, and scalars (will grow large if heavy use of recursive calls is made). These are small and easy/quick to handle.

What your JVM actually does is down to the JVM developer, but the above is generally true of most.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top