When a variable goes out of scope in Java, is it immediately removed from stack and one strong reference to the object it pointed to removed ?
daudiam
-6
Junior Poster
Recommended Answers
Jump to PostIf I understand the question, then the answer is "yes", but why do you ask, and what do you want to infer from the answer?
Jump to PostMost likely, most VMs will wait until a method goes out of scope to reset the stack frame - and thus you will have references that are out of scope but still on the stack. - but again this is up the VM writers.
Now the object being referenced …
Jump to PostLocal variables do not get garbage collected. They are allocated on the stack and thus automatically lost when the block is exited (the block in this case being the while {...}). The objects to which the variable refers are not on the stack, and are eligible for GC when there …
All 10 Replies
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
daudiam
-6
Junior Poster
HarryPad
0
Newbie Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
NormR1
563
Posting Sage
Team Colleague
daudiam
-6
Junior Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
daudiam
-6
Junior Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
daudiam
-6
Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.