Comment #3 on issue 756 by [email protected]: Memory leak by using child
injector and multibinder
http://code.google.com/p/google-guice/issues/detail?id=756
The attached patch file fixes the memory leak by updating WeakKeySet to use
a java.util.WeakHashMap as its internal data structure.
The patch was created against the master branch using 'git format-patch'.
Multibinders create "unique" keys for each binding that is a member of the
collection (set or map). If multibinders are used in child injectors, then
the unique keys are added to the parent's blacklist. If child injectors are
routinely created, then this leads to a memory leak where more and more
Multibinding keys are added to the blacklist.
The patch changes the WeakKeySet class (which manages the blacklist) to use
true weak references. When the child injector is eligible for garbage
collection, so will the keys it contributed to the blacklist (thus
eliminating the memory leak).
It is possible that something else will hold strong references to the keys,
but that is almost certainly NOT the case for Multibinding keys because
only the Multibinder and the child injector are aware of the keys. As such,
any unintended affects that may exist by others holding strong references
to the keys are highly unlikely to occur in practice (because the user code
would have to be doing something ridiculous).
This is a more general fix than fixing the Multibinder RealElement.toString
method (which would only fix the Multibinder extension and not third-party
or future extensions).
Attachments:
0001-Fixes-WeakKeySet-to-use-real-weak-references.patch 3.7 KB
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
--
You received this message because you are subscribed to the Google Groups
"google-guice-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice-dev.
For more options, visit https://groups.google.com/d/optout.