Page 1 of 1

Memory Management

Posted: 13 Feb 2011, 05:55
by smilefr
I know java has a garbage collector, but i don't really know how it behaves;

For example if i have an SFSObject A that contains an SFSObject B inside it, and a String "Hello" inside B, If i do:

(we assume "key of B" is the index of B)

Code: Select all

A.removeElement("Key of B")
Is "Hello" still somewhere inside the Memory? Or will the garbage collector remove it since it has no link?

Thank you,

smilefr

Posted: 13 Feb 2011, 17:13
by tchen
When nothing can see it, it'll be removed - maybe.

The GC has a couple generations. When something goes out of scope and it can readily determine nothing has a reference, it'll collect it almost instantly.

If it can't easily determine it, it starts to get moved into a older generation. As it gets older, it needs a hard-core mark-and-sweep collector. That's what you see when the JVM memory usage suddenly drops from the peak to the trough in the SFS admin panel.

So, depending on which generation it is in, you may or may not see it get removed :P