aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Garbage Collection problem?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Garbage Collection problem??" Watch "Garbage Collection problem??" New topic
Author

Garbage Collection problem??

Ravinder Rana
Greenhorn

Joined: May 10, 2006
Posts: 29


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

Joined: Feb 02, 2006
Posts: 2023
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

Joined: May 10, 2006
Posts: 29
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

Joined: Feb 02, 2006
Posts: 2023
How many instances of X are created from line 3 to 5?
Can you explain why u think 2 objects 4 GC?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Garbage Collection problem??
 
Similar Threads
Question on Garbage collection
Reg garbage collection
Garbage collection explanation
garbage collection
Garbage Collection question