aspose file tools*
The moose likes Performance and the fly likes CopyOnWriteArrayList memory footprint Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "CopyOnWriteArrayList memory footprint" Watch "CopyOnWriteArrayList memory footprint" New topic
Author

CopyOnWriteArrayList memory footprint

Reji Nair
Greenhorn

Joined: Feb 04, 2008
Posts: 4
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

Joined: Jul 08, 2003
Posts: 24166
    
  30

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.


[Jess in Action][AskingGoodQuestions]
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6657
    
    5

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.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Reji Nair
Greenhorn

Joined: Feb 04, 2008
Posts: 4

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

Thanks and Regards
Reji
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: CopyOnWriteArrayList memory footprint
 
Similar Threads
error with latest jdk
dragdrop-colections
How to delete an index.
Mock question for ArrayList ( Drag and drop )
can we add primitive variables in ArrayList or just objects?