wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Head First Java Be the Garbage Collector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Head First Java Be the Garbage Collector" Watch "Head First Java Be the Garbage Collector" New topic
Author

Head First Java Be the Garbage Collector

David Busby
Greenhorn

Joined: Oct 24, 2010
Posts: 4
In the main method, what does GC gc1; do?

In class doStuff2, what does GC localGC do?
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

Please post the code.


Mohamed Sanaulla | My Blog
David Busby
Greenhorn

Joined: Oct 24, 2010
Posts: 4
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11411
    
  16

it creates a reference to a GC type of object, although it does not create one. It's like giving you a blank address card, saying "This WILL hold the address to a restaurant, somday"


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Sunny Jain
Ranch Hand

Joined: Jul 23, 2007
Posts: 433

Hi,

If you analyze reference of each object -

gc1 --> null
gc2 --> some object on heap
gc3 --> some object on heap
gc4 --> gc3

gc1 --> reference to object returned by doStuff --> create localGC (--> refer some object on heap) ---> passing same reference to doStuff2 (it does nothing with it) --> return the reference of localGC.
so overall -

gc1 --> refere to same object which localGC was assigned in dostuff method.


Garbage Collector and finalize

Thanks and Regards,
SCJP 1.5 (90%), SCWCD 1.5 (85%), The Jovial Java, java.util.concurrent tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Head First Java Be the Garbage Collector