This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of TensorFlow 2.0 in Action and have Thushan Ganegedara on-line!
See this thread for details.
Win a copy of TensorFlow 2.0 in Action 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
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Garbage Collector doubt (Examlab Diagnostic Test) Q4

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
source: (Examlab Diagnostic Test) Q4

Q. How many objects are eligible for Garbage Collector, after executing the Line-12 of the following program?


I am confused to solve this problem. Any clue would be highly appreciated.
 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to analyse this using pen and paper, find out how many objects are created in total and then check out how many gets derefrenced.
I guess 4 new objects are created in this scenario and finally 1 becomes eligible for GC

Cheers-
Joshua
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Sridhar Gudipalli wrote:source: (Examlab Diagnostic Test) Q4

Q. How many objects are eligible for Garbage Collector, after executing the Line-12 of the following program?


I am confused to solve this problem. Any clue would be highly appreciated.


I am confused too, but IMHO 0 object ?
There is a scheme but I 'm not sure 100%



22052010(004).jpg
[Thumbnail for 22052010(004).jpg]
scheme
 
Sridhar Gudipalli
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rufat Piriyev wrote:
I am confused too, but IMHO 0 object ?
There is a scheme but I 'm not sure 100%



Thanks for trying to solve. But the answer is 1. I tried to draw this object creation. But still not clear with the flow.
 
Joshua Antony
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer is 1 because a2.a=null frees an object therby making it eligible for GC. I am sure you can find out if you try a bit harder

Cheers-
Joshua
 
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer is clearly 1.

a2-->[ Object A1 (IV) ]---->Object A2
a3--->[Object A3 (IV) ]---->Object A1
a1---->Object A3
[Object A3 (IV) ] ---->Object A4
Line12 a2.null cause AI object to be eligible for Garbage Collection.


Note:- [Object A1 (IV) )----> by this link i mean Object A1's Instance Variable(IV) is Pointing to

I have numbered Object A's just to make it bit easier....so A1 A2 A3 and A4 are all Object A.

Thanks !!!
 
PI day is 3.14 (march 14th) and is also einstein's birthday. And this is merely a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic