Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: Garbage collection not happening?
> MyObject mo;
> List l = new ArrayList();
> while (rs.next())
> {
> mo = new MyObject();
> mo.setData1(rs.getString("data1"));
> mo.setData2(rs.getString("data2"));
> ...many more similar calls...
> l.add(mo);
> }
In the example you gave above none of the MyObjects can get garbage collected because each one has a reference remaining within the array list. In the second example you gave below, the objects are all available for garbage collection straight away.
> for (int i = 0; i < 10000; i++)
> {
> new ArrayList(10000);
> new String();
> new StringBuffer(100000);
> }
In short, objects are only available for garbage collection when the garbage collector determines that the program can no longer access them. Even then, there is no guarantee when or if redundant objects will be collected: it pretty much depends on the garbage collector implementation. Received on Mon Sep 02 2002 - 06:06:26 CDT
![]() |
![]() |