String alpha = new String("Red Rose") ; alpha = null; . . .
The first statement does two things:
String object is created,
containing the characters "Red Rose".
Then, (2) a reference
to that object is saved in the reference variable
The second statement assigns the value
When this happens,
the reference to the object is lost.
Since there is no reference to the object elsewhere,
it is now garbage.
The line through the box in the second statement
The object still exists in memory.
The memory it consists of will eventually be
the garbage collector
and will be made available for new objects.
Examine this (slightly altered) snippet of code:
String alpha = new String("Red Rose"); String beta = alpha; alpha = null; . . .