Joanne
Originally posted by Susan Smith:
I see. So it seems that arrayList.clear() is prone to memory leak.
Joanne
"I'm not back." - Bill Harding, Twister
Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
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?
Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
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.
"I'm not back." - Bill Harding, Twister
"I'm not back." - Bill Harding, Twister
joke time: What is brown and sticky? ... ... ... A stick! Use it to beat this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|