CameraX memory leak
See original GitHub issueDownload CameraX sample.
Add new empty activity.
Add LeakCanary dependency and
LeakSentry.refWatcher.watch(this)
to onDestroyView
of CameraFragment
.
After app started and all permissions granted start new activity and call finish on MainActivity
.
Like this f.x.
Handler().postDelayed({
startActivity(Intent(this, TestActivity::class.java))
finish()
}, 10000L)
You will see CameraX instance is leaking. Some screens from my app. In your sample leaks are the same.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Memory leak on official CameraX sample - Google Groups
I was using CameraX on our current project and getting some ridiculous crashes at fragments that implements camera preview use case, ...
Read more >Memory leak on official CameraX sample? : r/androiddev
I was using CameraX on our current project and getting some ridiculous crashes at fragments that implements camera preview use case, ...
Read more >Memory leak on CameraX preview use case - Stack Overflow
I was using CameraX on our current project and getting some ridiculous crashes at fragments that implements camera preview use case, ...
Read more >Memory leak from PreviewView [240077164] - Issue Tracker
According to the leaking stack information, it seams like that your app has a CameraEnhancer class that will hold the Preview use case...
Read more >CameraX | Android Developers
CameraX is an addition to Jetpack that makes it easier to add camera ... Fixed a memory leak caused by multiple threads concurrently...
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
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
I am facing the same issue, but @ocarey 's workaround sometimes crashes the app. I’ve also noticed that for every instance of the activity that’s leaked, there is also a leaked androidx.lifecycle.ReportFragment, so I’m guessing that it’s a bug in the camera lifecycle library (androidx.camera:camera-lifecycle)
By adding this to Activity onDestroy() I was able to force a Garbage Collection of my Camera Activity. Version alpha09 w/ CameraXBasic example app:
Best, Owen