Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 369479 - Allow WeakIdentityMap cleanupSize to be set
Summary: Allow WeakIdentityMap cleanupSize to be set
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-24 03:29 EST by Andreas Nader CLA
Modified: 2022-06-09 10:29 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Nader CLA 2012-01-24 03:29:19 EST
Build Identifier: 2.2.0.v20110202-r8913

The cleanup code in the WeakIdentityMap sets the cleanupSize to the size of the map. If the map has a lot of elements the cleanupSize may be set very high. In our application the heap may be filled up with a lot of empty CacheKeys that are never removed, because the cleanupSize is not reached any more.

We fixed the problem with overriding the code with this method setting a max cleanupsize to 1000:

  protected void checkCleanup() {
    super.checkCleanup();

    if (cleanupSize>MAXWEAKCLEANUPSIZE) {
      cleanupSize=MAXWEAKCLEANUPSIZE;
    }
  }

Reproducible: Didn't try
Comment 1 Tom Ware CLA 2012-02-09 10:51:19 EST
Converting to an Enhancement request.

We should allow the cleanup size to be something other than the size of the map.
Comment 2 Aliaksei Lahachou CLA 2017-08-22 10:26:27 EDT
We have a similar problem: I'm looking at a dump, which has more than 800000 WeakReferences that reference nothing. WeakReferences, HashEntries, LinkedNodes, and ReferenceCacheKeys alone account for more than 200 MB RAM. And that's for empty cache!

One of the biggest SoftCacheWeakIdentityMaps has the cleanupSize=105471 and the cleanupCount=8784. If I understand the code of WeakIdentityMap correctly, I have to put almost 100000 objects to trigger the next cleanup.

I believe allowing to set the cleanup size is not really a fix. The problem seems to be that it is unknown whether there are any dead keys in the map, so the whole map is scanned periodically. Instead, it would be better to create references with a ReferenceQueue and avoid scanning the map completely (similar to what java.util.WeakHashMap does).
Comment 3 Eclipse Webmaster CLA 2022-06-09 10:29:16 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink