Closed GoogleCodeExporter closed 9 years ago
The code above never releases the objects so its pretty obvious it should crash.
If you fix it to something like this it will work:
while (true) {
List<Node> list = new ArrayList<Node>();
for (int i = 0; i < 100; i++) {
list.add(new Node());
}
list.clear();
try {
Thread.sleep(10);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
The old VM is slightly more efficient in RAM object storage but if it does run
indefinitely this could be a bug there since this code MUST crash... E.g when
list.size() exceeds RAM.
Original comment by shai.almog
on 29 Jan 2015 at 2:58
Hi
I do not agree with your answer. A new ArrayList is created and assigned
to the 'list' variable at every iteration, meaning that the ArrayLists
from previous iterations are no longer live and should be garbage collected.
I tested and it is true that the code works by adding a list.clear(),
but it should also work without it: The loop is adding items
to a *different* new ArrayList at every iterations of the while loop,
and ArrayList instances from previous iterations are not referenced and
are hence garbage.
Nicolas
Le 1/29/2015 3:58 PM, codenameone@googlecode.com a écrit :
Original comment by tachyon....@gmail.com
on 29 Jan 2015 at 3:31
I missed that. Does this still happen in the current update, we made some GC
fixes today.
Original comment by shai.almog
on 29 Jan 2015 at 3:49
I tried again today, and the problem has gone.
Thanks.
Le 1/29/2015 4:49 PM, codenameone@googlecode.com a écrit :
Original comment by tachyon....@gmail.com
on 30 Jan 2015 at 4:10
Original comment by shai.almog
on 30 Jan 2015 at 7:20
Original issue reported on code.google.com by
tachyon....@gmail.com
on 29 Jan 2015 at 2:26Attachments: