Example:
public void foo() {
A a = new A();
}
What if there is this sequence of events?
- Java allocates memory for A.
- The
A()constructor runs. Now there is an instance in the heap. - The GC runs.
- There are no refs to the object and it is removed before being assigned to
a.
How does it prevent this from occurring? I would greatly appreciate links to article where it is explained.