• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Garbage Collection

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
I was reading through and found that in following codes

#1

At (1) 3 objects are eligible for garbage collection.


#2

At (2) 4 objects are eligible for garbage collection


#3


Please tell me whether i am right and where i am right and where i am going wrong??
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ishani sharma wrote:At (1) 3 objects are eligible for garbage collection.


No. You are still in the main method, so no objects are eligible for GC

ishani sharma wrote:At (2) 4 objects are eligible for garbage collection


As you only create 3 objects, that's highly unlikely.

ishani sharma wrote:At (3) 3 objects are eligible which are i2, i3, i4 and the objects i2.i, i3.i, i4.i are not eligible


Again, you are only creating 3 objects.

i2, i3, i4, i2.i, i3.i and i4 are object references. These are never garbage collected - only objects are garbage collected. Object references refer to objects and you can have several references referring to a single object. You need to work out which references refer to which objects and then once you've done this, if there is an object with no references, it will be eligible for GC.
 
Ranch Hand
Posts: 144
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

At (1) 3 objects are eligible for garbage collection.



At (1) in the main scope no objects are eligible for GC , however when main method completes threee objects are eligible for garbage collection


At (2) 4 objects are eligible for garbage collection



At(2) no objects are eligible for GC.





At (3) 3 objects are eligible which are i2, i3, i4 and the objects i2.i, i3.i, i4.i are not eligible



At(3) three(3) objects are eligible for GC.


 
ishani sharma
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check this thread

Henry Wong wrote

Four objects -- two Icelandic objects (created at line 11 and line 13) and the two Long objects contained in those two Icelandic objects.



Is what he said is wrong?? which objects are eligible at 15. ??
 
Hama Kamal
Ranch Hand
Posts: 144
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ishani sharma wrote:check this thread

Henry Wong wrote

Four objects -- two Icelandic objects (created at line 11 and line 13) and the two Long objects contained in those two Icelandic objects.



Is what he said is wrong?? which objects are eligible at 15. ??



what he said is perfectly right ..
 
ishani sharma
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hama can you please explain how 2 Long objects alongwith objects created at 11 and 13 are eligible??
 
Hama Kamal
Ranch Hand
Posts: 144
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ishani sharma wrote:Hama can you please explain how 2 Long objects alongwith objects created at 11 and 13 are eligible??



through inheritance each object on line 11 and 13 contains( Long weight) when the objects on line 11 and 13 become inreachable the Long objects become inreachable as well.
 
No matter how many women are assigned to the project, a pregnancy takes nine months. Much longer than this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic