• Post Reply Bookmark Topic Watch Topic
  • New Topic

Garbage Collection doubt  RSS feed

 
david colais
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Guys at the //do Stuff line how many objects are eligible for garbage collection.
 
Deepak Chopra
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
2.

Two object were created -

C1 ==> obj1 and Short1 obj
C2 ==> obj2 and Short2 obj

C3 ==> obj1.go(obj2) ==> null
C1 ==> null ( obj1, Short1 eligible for GC)

C2 ==> obj2, Short2 (still valid )
 
david colais
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My doubt is when you pass c2 to the go() method in the initialization of c3 object wont that object c2 also become null.
Please correct me if i am wrong...
 
Deepak Chopra
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, C2 will not be eligible for GC.

When you write -
C1.go(C2) --> you actually pass the reference of C2 object to other object, not the object itself.
so when you called this method -

C2 ==> refer to obj2
cb ==> refer to obj2

then you change cb referece -
cb = null

but C2 is still referring to obj2.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please QuoteYourSources.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!