Originally posted by Alexsandra Carvalho:
But think that: and if in method print() of t, the object is assign to another reference variable with use of "this" ???
Howdy, Le.
The answer is correct, after line one completes, the "t" object will be ready to be garbage collected.
If I understood what you said, I think you want to say something like this:
Is this it? If so, then, as soon as this method finishes, the "hello" object will be gone, since it is local.
After that, when you say "t = null;", in this case, there are no other references to the "new Teste()" object. So, it may be garbage collected.
To recommend JVM to collect this garbage, you can either call System.gc(); or Runtime.getRuntime().gc(); (it's just a recommendation, this will not force the VM to collect this garbage).