Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Paul Clapham
Ron McLeod
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Saloon Keepers:
Tim Holloway
Carey Brown
Roland Mueller
Piet Souris
Bartenders:
Forum:
Programmer Certification (OCPJP)
Garbage Collection problem??
Ravinder Rana
Greenhorn
Posts: 29
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Given the following, 1. public class X { 2. public static void main(String [] args) { 3. X x = new X(); 4. X x2 = m1(x); 5. X x4 = new X(); 6. x2 = x4; 7. doComplexStuff(); 8. } 9. static X m1(X mx) { 10. mx = new X(); 11. return mx; 12. } 13. } After line 6 runs. how many objects are eligible for garbage collection? A. 0 B. 1 C. 2 D. 3 E. 4
i think 2 objects r eligible 4 garbage collection(at line 4).
I'm a bit confuse,plz explain this garbage collection regarding in method return.
Thanks in advance.
wise owen
Ranch Hand
Posts: 2023
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Only one object.
3. X x = new X(); //create one. x references to it
4. X x2 = m1(x); //create one in m1 method. x2 references to it
5. X x4 = new X(); //create one. x4 references
6. x2 = x4; //x2 references to x4's object. x2 originally referenced object can be GC.
Ravinder Rana
Greenhorn
Posts: 29
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks 4 reply,
Wise Owen u r saying, X x=new X();//creat one
I think it creates two objects, then how one object eligible 4 garbage colln.
Plz clear it to me, I'm a bit confuse.
Thanks in advance.
wise owen
Ranch Hand
Posts: 2023
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
How many instances of X are created from line 3 to 5?
Can you explain why u think 2 objects 4 GC?
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Reg garbage collection
garbage collection
Garbage collection explanation
Garbage Collection question
Question on Garbage collection
More...