Governator is a library of extensions and utilities that enhance Google Guice to provide: classpath scanning and automatic binding, lifecycle management, configuration to field mapping, field validation and parallelized object warmup.
Apache License 2.0
825
stars
180
forks
source link
fix memory leak for OptionalBinder with PreDestroy #392
If OptionalBinder is used with a type that has a PreDestroy
method, then PreDestroyMonitor will add a cleanup action each
time that type is injected. If this happens a lot, e.g. using
it with RequestScoped, then it can quickly fill up the heap
and cause OOM.
@tcellucci The optional* test cases reproduce the issue. Trying
your suggestion of just ignoring bindings with no scope seems to
have worked in that it passed the tests (I needed to add a scope to
one class for some Nullable tests). I don't know if it is the best way
to fix this issue, but it should avoid the memory leak.
To keep the context in one place, @twicksell has some concerns about ignoring the cleanup for the unscoped objects. The Governator maintainers are investigating an alternative fix.
If OptionalBinder is used with a type that has a PreDestroy method, then PreDestroyMonitor will add a cleanup action each time that type is injected. If this happens a lot, e.g. using it with
RequestScoped
, then it can quickly fill up the heap and cause OOM.@tcellucci The
optional*
test cases reproduce the issue. Trying your suggestion of just ignoring bindings with no scope seems to have worked in that it passed the tests (I needed to add a scope to one class for some Nullable tests). I don't know if it is the best way to fix this issue, but it should avoid the memory leak./cc @vfilanovsky