{"action":"created","issue":{"url":"https://api.github.com/repos/google/guice/issues/910","labels_url":"https://api.github.com/repos/google/guice/issues/910/labels{/name}","comments_url":"https://api.github.com/repos/google/guice/issues/910/comments","events_url":"https://api.github.com/repos/google/guice/issues/910/events","html_url":"https://github.com/google/guice/issues/910","id":63260255,"number":910,"title":"TypeLiteral configured in child Injector leaked into parent Injector","user":{"login":"moreginger","id":1387874,"avatar_url":"https://avatars.githubusercontent.com/u/1387874?v=3","gravatar_id":"","url":"https://api.github.com/users/moreginger","html_url":"https://github.com/moreginger","followers_url":"https://api.github.com/users/moreginger/followers","following_url":"https://api.github.com/users/moreginger/following{/other_user}","gists_url":"https://api.github.com/users/moreginger/gists{/gist_id}","starred_url":"https://api.github.com/users/moreginger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/moreginger/subscriptions","organizations_url":"https://api.github.com/users/moreginger/orgs","repos_url":"https://api.github.com/users/moreginger/repos","events_url":"https://api.github.com/users/moreginger/events{/privacy}","received_events_url":"https://api.github.com/users/moreginger/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-20T16:35:35Z","updated_at":"2015-03-20T16:38:50Z","closed_at":null,"body":"Perhaps this behavior is known but I couldn't find any mention of it. This code...\r\n\r\n```java\r\n public static void main(final String[] args) {\r\n    Injector parent = Guice.createInjector();\r\n\r\n    parent.createChildInjector(createModule(new GiantObject(\"notleaked\")));\r\n\r\n    // GiantObject(\"notleaked\") can be garbage collected.\r\n\r\n    parent.createChildInjector(createTypeLiteralModule(new GiantObject(\"leaked\")));\r\n\r\n    // GiantObject(\"leaked\") cannot be garbage collected.\r\n  }\r\n\r\n  private static AbstractModule createModule(final GiantObject o) {\r\n    return new AbstractModule() {\r\n      @Override\r\n      protected void configure() {\r\n        bind(GiantObject.class).toInstance(o);\r\n      }\r\n    };\r\n  }\r\n\r\n  private static AbstractModule createTypeLiteralModule(final GiantObject o) {\r\n    return new AbstractModule() {\r\n      @Override\r\n      protected void configure() {\r\n        bind(new TypeLiteral<GiantObject>() {\r\n        }).toInstance(o);\r\n      }\r\n    };\r\n  }\r\n```\r\n\r\n...puts a reference to the TypeLiteral<GiantObject> in the parent Injector, and appears never to be garbage collected. JProfiler lists InheritingState/WeakKeySet in the first GC root. This leaks whatever is in scope for the TypeLiteral (i.e. the GiantObject(\"leaked\") instance)."},"comment":{"url":"https://api.github.com/repos/google/guice/issues/comments/84064169","html_url":"https://github.com/google/guice/issues/910#issuecomment-84064169","issue_url":"https://api.github.com/repos/google/guice/issues/910","id":84064169,"user":{"login":"moreginger","id":1387874,"avatar_url":"https://avatars.githubusercontent.com/u/1387874?v=3","gravatar_id":"","url":"https://api.github.com/users/moreginger","html_url":"https://github.com/moreginger","followers_url":"https://api.github.com/users/moreginger/followers","following_url":"https://api.github.com/users/moreginger/following{/other_user}","gists_url":"https://api.github.com/users/moreginger/gists{/gist_id}","starred_url":"https://api.github.com/users/moreginger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/moreginger/subscriptions","organizations_url":"https://api.github.com/users/moreginger/orgs","repos_url":"https://api.github.com/users/moreginger/repos","events_url":"https://api.github.com/users/moreginger/events{/privacy}","received_events_url":"https://api.github.com/users/moreginger/received_events","type":"User","site_admin":false},"created_at":"2015-03-20T16:38:50Z","updated_at":"2015-03-20T16:38:50Z","body":"JProfiler object graph to GC root.\r\n\r\n![graph](https://cloud.githubusercontent.com/assets/1387874/6756094/83a8ce8a-cf1f-11e4-88a6-916eee704b48.png)\r\n"}}