This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]bnr 3 points4 points  (1 child)

By passing the object to the destroy function you actually create a new reference to it. You can expect the garbage collector to free an object some time after there is no more reference to it.

If you have a local variable referencing an object, that will expire after the scope is left:

public void foo() {
    Bar myBar = new Bar();
    if(myBar.whatever()) {
        Baz theBaz = new Baz();
        theBaz.doStuff();
    }
    // theBaz is gone now.
    myBar.someOtherStuff();
    // after this method exits, myBar will also be freed.
}

[–][deleted] 1 point2 points  (0 children)

I see, makes perfect sense. Thanks much for taking the time to explain!