• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem in Garbage collector

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
code source:-exam lab question
//at line 9 c.aob and c.aob both are referring to null:
but the object to which B and c are referring to still can be accessed by a.aob as in line4
please help
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This kind of questions are frequently asked here. You may search a little in the forum and could find many threads which discussed about this. Easiest way to solve these kinds are by drawing an object graph in a paper. Not getting your question though...

//at line 9 c.aob and c.aob both are referring to null:


You are talking about the same reference (i.e: c.aob) here?

but the object to which B and c are referring to still can be accessed by a.aob as in line4


Yes, the reference "a" is still alive (I guess you meant b, not B..).
 
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will expect someone to comment if i am wrong.




so answer of this Question is 1.only 1 object will be eligible for Garbage collection.
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try to solve this kind of problem by drawing diagram.It will be good for you and remember the links which got broken will only be eligible for gc if they are not be refer by anyone then.
 
Ranch Hand
Posts: 276
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do we draw object graphs/diagrams? someone got any link that explains it?
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
click on this link http://cs.wellesley.edu/~cs111/fall97/lectures/ObjectDiagrams/object-diagrams.html may it will be helpful.
 
Vijitha Kumara
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

shanky sohar wrote:I will expect someone to comment if i am wrong.....


There is no use of reference "a" in line#7.

....so answer of this Question is 1.only 1 object will be eligible for Garbage collection.


No. Another one object from line#7 is eligible for GC (the one created in "...new A().aob...).
 
Vijitha Kumara
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Same question has been discussed here.
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
that really a tricky question,one of the great trick play is at line no 7.
now i have corrected my post because of above comment
correct answer is given below.



so now two objects are eligible for gc.
 
permaculture is a more symbiotic relationship with nature so I can be even lazier. Read tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic