Factory and Provider Memory Leak
See original GitHub issueI added LeakCanary to my app, and Iβve been getting reports that any class that uses a factory or provider binding is leaking a reference to a destroyed Activity.
I didnβt look too deeply into it, but it looks like the lambda in Factory.getFactory is capturing the BindingDI instance, which for some reason has a reference to my Activity in its context field. Iβm not sure how the activity got set as the context.
I use this scope but nothing in SomethingApi, SomethingManager, nor somethingFactory use it.
There is a class bound in an activitySingleton scope that uses SomethingManager but thatβs not referenced in the leak trace, it is bound after SomethingApi, and Iβve verified that it and activityScope has been properly destroyed.
β¬βββ
β GC Root: System class
β
ββ android.provider.FontsContract class
β Leaking: NO (MyAppβ is not leaking and a class is never leaking)
β β static FontsContract.sContext
ββ co.my.app.MyApp instance
β Leaking: NO (Application is a singleton)
β MyApp does not wrap an activity context
β β MyApp.kodein
β ~~~~~~
ββ org.kodein.di.LazyKodein instance
β Leaking: UNKNOWN
β β LazyKodein.baseKodein$delegate
β ~~~~~~~~~~~~~~~~~~~
ββ kotlin.SynchronizedLazyImpl instance
β Leaking: UNKNOWN
β β SynchronizedLazyImpl._value
β ~~~~~~
ββ org.kodein.di.internal.KodeinImpl instance
β Leaking: UNKNOWN
β β KodeinImpl._container
β ~~~~~~~~~~
ββ org.kodein.di.internal.KodeinContainerImpl instance
β Leaking: UNKNOWN
β β KodeinContainerImpl.tree
β ~~~~
ββ org.kodein.di.internal.KodeinTreeImpl instance
β Leaking: UNKNOWN
β β KodeinTreeImpl.bindings
β ~~~~~~~~
ββ java.util.HashMap instance
β Leaking: UNKNOWN
β β HashMap.table
β ~~~~~
ββ java.util.HashMap$Node[] array
β Leaking: UNKNOWN
β β HashMap$Node[].[89]
β ~~~~
ββ java.util.HashMap$Node instance
β Leaking: UNKNOWN
β β HashMap$Node.value
β ~~~~~
ββ java.util.ArrayList instance
β Leaking: UNKNOWN
β β ArrayList.elementData
β ~~~~~~~~~~~
ββ java.lang.Object[] array
β Leaking: UNKNOWN
β β Object[].[0]
β ~~~
ββ org.kodein.di.KodeinDefinition instance
β Leaking: UNKNOWN
β β KodeinDefinition.binding
β ~~~~~~~
ββ org.kodein.di.bindings.Singleton instance
β Leaking: UNKNOWN
β β Singleton.scope
β ~~~~~
ββ org.kodein.di.bindings.NoScope instance
β Leaking: UNKNOWN
β β NoScope._registry
β ~~~~~~~~~
ββ org.kodein.di.bindings.StandardScopeRegistry instance
β Leaking: UNKNOWN
β β StandardScopeRegistry._cache
β ~~~~~~
ββ java.util.concurrent.ConcurrentHashMap instance
β Leaking: UNKNOWN
β β ConcurrentHashMap.table
β ~~~~~
ββ java.util.concurrent.ConcurrentHashMap$Node[] array
β Leaking: UNKNOWN
β β ConcurrentHashMap$Node[].[0]
β ~~~
ββ java.util.concurrent.ConcurrentHashMap$Node instance
β Leaking: UNKNOWN
β β ConcurrentHashMap$Node.val
β ~~~
ββ org.kodein.di.bindings.SingletonReference$make$1 instance
β Leaking: UNKNOWN
β Anonymous subclass of kotlin.jvm.internal.Lambda
β β SingletonReference$make$1.$value
β ~~~~~~
ββ co.my.app.api.SomethingApiImpl instance
β Leaking: UNKNOWN
β β SomethingApiImpl.somethingManager
β ~~~~~~~~~~~~~
ββ co.my.app.models.something.SomethingManagerImpl instance
β Leaking: UNKNOWN
β β SomethingManagerImpl.somethingFactory
β ~~~~~~~~~~~~~
ββ org.kodein.di.bindings.Factory$getFactory$1 instance
β Leaking: UNKNOWN
β Anonymous subclass of kotlin.jvm.internal.Lambda
β β Factory$getFactory$1.$kodein
β ~~~~~~~
ββ org.kodein.di.internal.BindingKodeinImpl instance
β Leaking: UNKNOWN
β β BindingKodeinImpl.context
β ~~~~~~~
β°β co.my.app.main.MainActivity instance
β Leaking: YES (ObjectWatcher was watching this because co.myapp.main.MainActivity received Activity#onDestroy() callback and Activity#mDestroyed is true)
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Factory and Provider Memory Leak Β· Issue #301
My fix is to create another type of NoArgDIBinding that has the deferred behavior of Singleton and the context safe behavior of EagerSingleton...
Read more >Understanding Memory Leaks in Java
A Memory Leak is a situation where there are objects present in the heap that are no longer used, but the garbage collector...
Read more >Tackling memory leak - Performance investigations
Memory leak occurs if useless resources are not removed from memory β there has to be something rooting old data. Investigation plan:.
Read more >8 Ways You can Cause Memory Leaks in .NET
Memory leaks are sneakily bad creatures. It's easy to ignore them for a very long time, while they slowly destroy the application. With...
Read more >Memory Leak in ServerLocator.factories?
Hi all, We use HornetQ using JMS API in a web application. When a message needs to be sent, we use: con =...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Adressed in 9e6afe1535c7d1332f9bf1364ba1e8fdc0a6296e and published as
7.1.0-master-87
in dev repositoryfixed in 7.2