• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CopyOnWriteArrayList memory footprint

 
Reji Nair
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello experts,
I am using CopyonWriteArrayList in a multithreading environment in which traversal is quite often than mutation functions like addition,removal etc.
But when I check the heap dump using VisualVM, it is showing a very large number of Objects of CopyOnWriteArrayList is is getting created and garbage collected.
Please find the code sample below. I expect not more than three objects of the CopyOnWriteArrayList should be created in the following program. But in visualVM, it shows some figures around 12000.


Any help or suggestion is deeply appreciated.

Regards
Reji Nair
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure they are CopyOnWriteArrayList objects, or are they really something like "CopyOnWriteArrayList$1" objects? Each time you call iterator(), a new object is created, and that object is likely to be an anonymous inner class of CopyOnWriteArrayList. Such classes have names like CopyOnWriteArrayList$1, and if you're not paying attention, it's easy to mistake one for the other. So my guess is that the 12,000 objects are really the Iterators you're creating.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernest Friedman-Hill wrote:Are you sure they are CopyOnWriteArrayList objects, or are they really something like "CopyOnWriteArrayList$1" objects? Each time you call iterator(), a new object is created, and that object is likely to be an anonymous inner class of CopyOnWriteArrayList. Such classes have names like CopyOnWriteArrayList$1, and if you're not paying attention, it's easy to mistake one for the other. So my guess is that the 12,000 objects are really the Iterators you're creating.


That is correct. On the Sun JDK you can find a reference to the inner class COWIterator which takes a reference to each element that is to be iterated.
 
Reji Nair
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thank you Ernest,
Now I understand that those are the object of Iterator. I have mistaken them to CopyonWriteArrayList objects

Thanks and Regards
Reji
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic