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

Question about GC and Objects

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i stumbled about this Test in SCJP by Kat and bertes . ..

on page 274

Which two are true about the objects created within main(), and eligible for garbage collection when line 14 is reached?

the answer is FIVE objects are created and two object are eligible for GC...

can someone help me
explain please
 
Ranch Hand
Posts: 64
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


if you face this kind of question you need to draw diagram to know which reference is point to which object. which one is eligible to GC.
 
Christian Joseph
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i get it now, Thanks! Ms. Naveen Madarapu...

so whenever i say "new Dozens" it will crreate a Dozen Object, PLUS a instance member like the int in the example

then since "d" reference object "NEW DOZENS()" has pointing two f***n thing the "d" and the "d[1]", which is become null, the line broke and then the DOzen of d and the int object, where left on the blackhole

thanks ! did i get it?
 
Ranch Hand
Posts: 180
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The statement Dozens[] da = new Dozens[3] creates the first object i.e. a Dozens array (1). The statement da[0] = new Dozens() creates 2 objects i.e. a Dozens object (2) and an int array (3). The statement Dozens d = new Dozens() creates 2 objects i.e. a Dozens object (4) and an int array (5). Total objects created is 5.

The statements d = null and da[1] = null make objects (4) and (5) eligible for GC at line 14. Both statements are necessary or else objects (4) and (5) wont be eligible for GC at line 14.

 
Christian Joseph
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ogeh Ikem wrote:The statement Dozens[] da = new Dozens[3] creates the first object i.e. a Dozens array (1). The statement da[0] = new Dozens() creates 2 objects i.e. a Dozens object (2) and an int array (3). The statement Dozens d = new Dozens() creates 2 objects i.e. a Dozens object (4) and an int array (5). Total objects created is 5.

The statements d = null and da[1] = null make objects (4) and (5) eligible for GC at line 14. Both statements are necessary or else objects (4) and (5) wont be eligible for GC at line 14.


THANKS!!! IT REALLY help me alot hearing from you guys!!
 
In the renaissance, how big were the dinosaurs? Did you have tiny ads?
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic