I have a doubt regarding memory allocations in java,
What I understand from memory allocations to a program is ,
All the instance variables and objects created using the new operator are stored on the heap
And all the static variables created are stored in a special area called as static area.
So Once a class loads, all the static variables are initialized and the static methods been loaded.
Now what i wanted to make clear is ,
what happens when I create some objects in a static method,Can these objects be garbage collected once the execution of this method is over ??because what I could see is objects created in static method ,were still seen on heap...a Example of this was ,
whenever we call function trim() in string ,it internally calls the substring method ,which returns
new String(offset + beginIndex, endIndex - beginIndex, value)
so now for example if i'm doing something like,
So whenever now this MyClass is loaded ,myMethod would get executed as its a static one,so after execution of this method ,would the Strings temp and a be eligible for garbage collection or not?and do we refer to them as static variables because they are created in a static method?
Thanks All,Appreciate your valuable time.
[ September 18, 2006: Message edited by: Archies Gomes ]