This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes garbage collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "garbage collection" Watch "garbage collection" New topic

garbage collection

srinivas sridaragaddi
Ranch Hand

Joined: Jul 24, 2007
Posts: 225

SCJP 5.0<br /> <br />"Skills are started with learning and mastered with improvement. Nothing is hereditary except death" BUDDHA...
Srinivasan Mahadevan

Joined: Jun 21, 2002
Posts: 5
There are totally 5 objects created on the heap, NOT 8 objects. I think you have assumed that for new grab1[4], 4 objects have been created. Please note that it is just a single array object and not 4 objects. The 5 objects are as follows:
1 grab1 array object
4 grab1 objects

Out of these 5 objects, 3 grab1 objects (i.e. the first 3 created grab1 objects) are eligible for garbage collection. The last grab1 object and the grab1 array object will remain active and are not eligible for garbage collection. Please note that inside the method "f", you set array to null. This actually sets the copy of the reference to be set to null and the actual array reference in the main method remains unaffected and is not set to null.
I agree. Here's the link:
subject: garbage collection
It's not a secret anymore!