• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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: 24203
44
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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic