My question is related to:
- Java: What is the purpose of creating an object in the heap with no reference
- Java - Can objects which are executing methods be garbage-collected?
What actually happens when we have something like this in our code:
(new SomeClass()).longMethod();
Is there still some sort of unnamed (strong ?) reference pointing to the newly created object on Heap put on Stack?
If nothing is on Stack, then how does Garbage Collector know to preserve the object for the duration of the method?
Is it possibly the same as
{
// very local scope
SomeClass throwAwayRef = new SomeClass();
throwAwayRef.longMethod();
}