Java Reference
In-Depth Information
6. christmas = new GregorianCalendar(2009,12,25);
7. newyears = new GregorianCalendar(2010,1,1);
8.
9. christmas = newyears;
10. GregorianCalendar d = christmas;
11. christmas = null;
12. }
13. }
The two GregorianCalendar objects are created on lines 6 and 7, resulting in the
references and objects that Figure 1.8 shows.
FIGURE 1.8 Each GregorianCalendar object has a reference pointing to it.
christmas
day
25
month
12
year
2009
newyears
day
1
month
1
year
2010
On line 9, the christmas reference is assigned to newyears , which results in no more
references pointing to the object from line 6, so this object immediately becomes available
for garbage collection after line 9. There is now only one GregorianCalendar object (from
line 7) reachable in memory, and after line 10 there are three references pointing to it, as
Figure 1.9 shows.
Search WWH ::




Custom Search