Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Garbage Collections

 
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,

I am having a great deal of problems when I solve questions from garbage collections. In general the questions like, How many objects would be garbage collected. Is there any diagramatic way to solve such questions.

ThankS
Shashank
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, when you create a reference to a new object. Draw two boxes. One to for the stack, where the reference variable goes, and one for the heap where the Object instance goes. (Strings not included)

Then draw a line from the reference to the instance. This shows that the instance that is on the heap has a reference and is therefore not eligible for garbage collection yet.

If the instance creates new Objects then put that new object into the heap, but have the object atht is in the heap point to the new object in the heap.

So if you create another new object that the old reference variable will now point to, you will erase the previous line. When an object on the heap does not have a reference pointing to it from the stack, it is very possible that that is now eligible for garbage collection. The only time it won't be is if another object in the heap has a reference to that object, and some other reference from the stack points to that other object.

Islands are objects all on the heap that point to each other. As long as there is one reference, in the stack, that points to one of those objects in the heap, then all those heap objects that point to each other are still referenced and not eligible for garbage collection.

I hope that helps.

Mark
 
I am not young enough to know everything. - Oscar Wilde This tiny ad thinks it knows more than Oscar:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic