java - Method Created Objects Deleted on Exit -


this question has answer here:

are objects / fields created in method deleted upon exit of specific method?

example:

public static void createfolder() {      file folder = new file(c:\example\path "foldername");     folder.mkdir(); } 

would memory used store file "folder" deleted upon exit of "createfolder" method?

the file object referred folder becomes eligible garbage collection upon exit method since reference (folder) goes out of scope @ point.

when garbage collected impossible tell exactly, sometime after point.

more generally, local variables in method allocated on stack , deleted when go out of scope. if primitives (int, float, long, etc) cease exist immediately. if references (as in case) reference ceases exist object referred continues exist long reference exists. example, if createfolder() method return value of folder, , caller preserved reference in 1 of own variables, file object not (yet) eligible gc. when all references object cease exist object eligible gc. language not specify when gc occurs.

this complicated little esoteric topics having "weak" references can ignore time being.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -