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 PostIt seems to me that the variable results is declared in the scope of the while {...} block, and will remain in scope until the while loop is exited. At this point it beomes impossible to use that variable in any more code, so the question of exactly when its …
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.