Hacker News new | ask | show | jobs
by kdrakon 4099 days ago
Ah, yes, didn't consider that. But what about 'this'?; for what reason could the JVM choose to GC an object that the calling thread is currently running in? The example method exists in an instance of 'this' and isn't static.
1 comments

Execution in Java does not have a concept of "current object". 'this' is passed in a magic way, but it does not exist in a magic way. It's like any other variable, and can be collected as soon as it's not needed. Which can be extremely early, because optimizations can reduce the 'need' for a variable to only its side effects.

Go pick apart aggressively optimized and inlined code and I bet you can find situations where 'this' never even exists.