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?
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.