4

In the following code:

void method() {
   HeavyObject heavy = new HeavyObject();
   doStuffWith(heavy);
   doOtherStuff();
}

...can heavy be garbage collected before or during doOtherStuff()? JLS references preferred, though actual experiments would be cool too.

My goal is to determine whether or not heavy = null is strictly useless, or might conceivably have some benefit.

Louis Wasserman
  • 182,351
  • 25
  • 326
  • 397

0 Answers0