• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

CopyOnWriteArrayList memory footprint

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic