Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ch-assignment in kb ,need explanation of output:question 10

 
Arjun Srivastava
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

objects eliginle for garbage collection when line 12 is reached?
output:
five objects were created
and two objects are eligible for garbage collection.(second Dozens object and int array object)

please anyone explain me the answer how 5 objects are created here and why da[1] is eligible and why d is not?
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here in this program we will go step by step
here is the code

this create an array that is able to store 3 objects of type Dozens.
Remember that an array is always an object in java and here only one object is created and that is also of type Array
the three array elements can store objects of type Dozens but we have not created Dozen objects yet

This creates new Dozen object and now int[] dz is the instance member of class Dozens
so whenever we are creating Dozen object, in[] object is also getting created

again same, two a dozen object is created which has instance member int[] object
hence 2 more objects are created and the total number becomes 5 objects



now look into the code for terse explanation

hope this helps
Happy to help
happy preparation
 
Arjun Srivastava
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

da[1]=null; // here we make da[1] = null so the reference to the Dozen object is lost and also the in[] object in Dozen object is lost
hence two objects are eligible for garbage collection


thanks for wonderfull explanation ,one more thing
hence two objects are eligible for garbage collection
1. int [] object
2. is d or da[1] (because da[1] is never a object it was a reference to d),please clear this thing also??
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
da[1] is not object and d is not an object also
even d is not the object
they both are the reference variables
and also
if there is some statement like

then do not assume that da[1] is referring to d
that means that
THIS IS CORRECT
da[1] is referring to the object that is referred by the reference variable d

IT IS NOT
da[1] is referring to d

above statement is completely wrong

 
Arjun Srivastava
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks sir ,it really helps!!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic