Originally posted by Susan Smith:
I see. So it seems that arrayList.clear() is prone to memory leak.
Originally posted by Bill Shirley:
I would generally suggest you don't need to reuse an ArrayList for a different use. If you're done with it, toss it.
Originally posted by Andre Brito:
...Then, that ArrayList is for the GC (a), right?
Susan - that's correct. At least for the current implementation of ArrayList, and I think it's always been true. You can use the trimToSize() method to fix this if you like. It's not exactly a memory leak in the traditional sense - it doesn't keep growing. But whatever was the maximum size ever used by the ArrayList (for valid non-memory-leak reasons), that maximum size will be retained even when it's no longer necessary.