Export to GitHub

google-collections - issue #307

OutOfMemoryError when using MapMaker and Soft/Weak-Keys/Values


Posted on Dec 14, 2009 by Happy Elephant

Hi,

I assume, you are well aware of this behavior and that it is not really considered a bug. However, I am still reporting it, because I could not find any reference to it in the issues or groups.

Problem: When using soft/weak-keys/values one might expect, that using the map will never consume too much memory. This expectation stems from behavior of soft/weak-references in general and from java.util.WeakHashMap in particular, for which this expectation holds.

Observed: Continuously adding elements (very fast) to a MapMaker-map with (any combinaton of) soft/weak-keys/values leads to an OOME eventually.

Steps to reproduce: Launch the attached test case with -Xmx20M. (Or use more memory and increase the number of added elements.) The java.util-map will work as expected, but the MapMaker-maps will throw OOMEs (or related errors).

More information: After having looked at the implementation of WeakHashMap and MapMaker, I would guess, that the Google-Finalizer-Thread is starved by GC, thus cannot free memory by removing Entries, and thus is starved even more by GC. This vicious circle leads to OOME in the end. The util-map seems not to have this problem, since it removes old Entries when elements are added and thus memory usage cannot overtake memory release. Just guessing of course. :)

P.S.: I would really love to use this map as a cache in my application, but I am unsure if I can (since I obviously don't want OOME because of caching). So I would be very grateful if you could comment on the seriousness of this defect in your opinion.^

Thank you Johannes

Attachments

Comment #1

Posted on Jan 5, 2010 by Happy Wombat

This issue has been moved to the Guava project (keeping the same id number). Simply replace 'google-collections' with 'guava-libraries' in your address bar and it should take you there.

Status: Moved