Issue 307 in google-collections: OutOfMemoryError when using MapMaker and Soft/Weak-Keys/Values

2 views
Skip to first unread message

codesite...@google.com

unread,
Dec 14, 2009, 5:00:49 AM12/14/09
to google-coll...@googlegroups.com
Status: New
Owner: ----

New issue 307 by woidjoe: OutOfMemoryError when using MapMaker and
Soft/Weak-Keys/Values
http://code.google.com/p/google-collections/issues/detail?id=307

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:
MemoryBug.java 1.6 KB

--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
Reply all
Reply to author
Forward
0 new messages