-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak risk with @FeatureToggle Instance<Boolean>
and @FeatureVariant Instance<?>
#221
Comments
@gwenneg thank you for checking the implementation. Could we change the implementation to avoid the memory leak? |
If the leak is confirmed (which I'll try to check next week), there are several ways to "fix" it. One of them would be a simple doc update, showing how to destroy the try (Instance.Handle<Boolean> toggleHandle = toggle.getHandle()) {
boolean toggleValue = toggleHandle.get();
// do something with toggleValue
} There are other approaches such as using a wrapper class for the toggle field. But before considering any changes, the leak has to be confirmed 😄 |
Hey @mkouba! Is there something in Arc that prevents memory leaks when a public class FooProducer {
@Produces
@Dependent
Foo produce() {
return new Foo();
}
}
@ApplicationScoped
public class LongLivedBean {
@Inject
Instance<Foo> foos;
public void doSomething() {
Foo foo = foos.get();
// use foo without calling foos.destroy(foo) eventually
}
} I expected a potential memory leak in this extension but my profiler showed a healthy memory so I may be missing something... 😅 |
So both Weld and ArC try to mitigate this problem in a way that only some references to In ArC, we only add a In your case, there is a producer with no disposer and no CC @manovotn |
Awesome 🎉 Thanks for the detailed explanation! |
Yea, I can confirm this is the case even for Weld (code here). That being said, you should handle the bean properly and destroy it when no longer needed (assuming it is intended that those beans are dependent and repeated invocations generate new instances OFC). |
From what I saw in the extension code, when
@FeatureToggle Instance<Boolean>
or@FeatureVariant Instance<?>
are used, the injected bean doesn't have an explicit CDI scope which means it defaults to@Dependent
.When a
@Dependent
bean is injected withInstance<?>
into an@ApplicationScoped
or@Singleton
bean and is no destroyed when it's no longer needed, it stays in the memory forever, so there's basically a memory leak.Is there a risk of memory leak with this extension, or did I miss something? If there is a risk of leak, the doc should at least explain how to prevent it and show how the injected bean can be destroyed.
The text was updated successfully, but these errors were encountered: