Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
20 events
when toggle format what by license comment
Aug 30, 2015 at 16:34 history edited Marko Topolnik CC BY-SA 3.0
deleted 31 characters in body
Nov 29, 2012 at 11:18 vote accept Evgeniy Dorofeev
Nov 26, 2012 at 16:31 history wiki removed casperOne
Nov 23, 2012 at 22:44 comment added Marko Topolnik @meriton Yes, from the practical standpoint it is quite clear what is happening in each case, except (for me, at least) how exactly interpreted code manages to release the object allocated in the loop, since the bytecode doesn't indicate it will happen. Apparently scope does somehow influence this, although clearly in no obvious way.
Nov 23, 2012 at 22:32 comment added meriton Since the scope of variables is lost in translation to bytecode it can not affect garbage collection (unless the compiler choose to resuse the local variable). But yes, the spec is quite vague on what does affect garbage collection. Practically speaking though, all major JVMs identify garbage by a reachability analysis, the root set of which includes the active frames.
Nov 23, 2012 at 21:24 history edited Marko Topolnik CC BY-SA 3.0
added 53 characters in body
Nov 23, 2012 at 21:17 comment added Marko Topolnik @meriton So all the spec has to say is that the objects become unreachable when the method as a whole completes. Nothing is said of variables in or out of scope; also nothing specific is required to happen to an unreachable object at any particular time.
Nov 23, 2012 at 21:01 comment added meriton Admittedly, "the Java virtual machine assumes no particular type of automatic storage management system".
Nov 23, 2012 at 20:57 comment added meriton ... but the Java Virtual Machine Specification describes the internal data structures of the VM. In particular, it writes that local variables are stored in a frame, and the frame is destroyed when the method invocation completes. Similarly, the JVM spec mandates the use of an "automatic storage management system (known as a garbage collector)".
Nov 23, 2012 at 19:32 history edited Marko Topolnik CC BY-SA 3.0
added 42 characters in body
Nov 23, 2012 at 19:18 history edited Marko Topolnik CC BY-SA 3.0
added 23 characters in body
Nov 23, 2012 at 19:07 history edited Marko Topolnik CC BY-SA 3.0
added 16 characters in body
Nov 23, 2012 at 19:02 history edited Marko Topolnik CC BY-SA 3.0
added 1337 characters in body
Nov 23, 2012 at 17:03 history edited Marko Topolnik CC BY-SA 3.0
deleted 27 characters in body
Nov 23, 2012 at 16:37 history edited Marko Topolnik CC BY-SA 3.0
added 38 characters in body
Nov 23, 2012 at 16:31 history edited Marko Topolnik CC BY-SA 3.0
added 6 characters in body
Nov 23, 2012 at 16:25 history edited Marko Topolnik CC BY-SA 3.0
added 75 characters in body
Nov 23, 2012 at 15:37 history edited Marko Topolnik CC BY-SA 3.0
added 896 characters in body
Nov 23, 2012 at 15:18 history edited Marko Topolnik CC BY-SA 3.0
added 47 characters in body
Nov 23, 2012 at 15:05 history answered Marko Topolnik CC BY-SA 3.0