cllanjim / google-collections

Automatically exported from code.google.com/p/google-collections
Apache License 2.0
0 stars 0 forks source link

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

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
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

Original issue reported on code.google.com by woid...@gmail.com on 14 Dec 2009 at 10:00

Attachments:

GoogleCodeExporter commented 8 years ago
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.

Original comment by kevinb@google.com on 5 Jan 2010 at 11:09