Discussion:
When is the google guice injector garbage collected?
vishesh gupta
2017-11-17 05:54:59 UTC
Permalink
When we are no more referencing a google guice injector in the application,
when will be the resources held by the injector, like Singletons, released
or garbage collected?

To illustrated more, consider this code snippet:

public void someFunction() {Injector injector = Guice.createInjector(new DataStoreBindings());DataTransactor transactor =
injector.getInstance(DataInfoTransactor.class);
transactor.doSomething(); }

Some singleton bindings are also created by this injector. When this
function ends the Injector instance will go out of scope and application
has no way to refer this Injector again.

I want to know, if the injector will be garbage collected? If yes, then
what will happen to the singletons held by the injector?
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/b2ec2692-0833-45b4-a85d-23adb6900ae4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Stephan Classen
2017-11-17 09:26:36 UTC
Permalink
They will also get garbage collected unless they have been injected somewhere. Then they only get garbage collected once the objects holding these references are also garbage collectable.
In short. Guice does not change any behavior of the GC. The injector and all created instances (singleton or not) will get collected when they are not reachable. Just like any other java object.
And because this question may arise as a follow up:
Singletons are not global singletons. They are singletons per injector instance. So guice will not hold a reference in some static field.
Post by vishesh gupta
When we are no more referencing a google guice injector in the
application,
when will be the resources held by the injector, like Singletons, released
or garbage collected?
public void someFunction() {Injector injector =
Guice.createInjector(new DataStoreBindings());DataTransactor transactor
=
injector.getInstance(DataInfoTransactor.class);
transactor.doSomething(); }
Some singleton bindings are also created by this injector. When this
function ends the Injector instance will go out of scope and
application
has no way to refer this Injector again.
I want to know, if the injector will be garbage collected? If yes, then
what will happen to the singletons held by the injector?
--
You received this message because you are subscribed to the Google
Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-guice/b2ec2692-0833-45b4-a85d-23adb6900ae4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/17D931C3-5136-4C2D-ACAC-3B23833B68F6%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.
Loading...