Static Context
- Dominant language
- Kotlin
- Stars
- 5.6k
- Forks
- 2k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 92
Description
https://github.com/nextcloud/android/blob/f04f500669b1ea3c9fc85eb022b10f4345ae464e/src/main/java/com/owncloud/android/MainApp.java#L101-L101
> Do not place Android context classes in static fields; this is a memory leak (and also breaks Instant Run) less...
A static field will leak contexts. Non-static inner classes have an implicit reference to their outer class. If that outer class is for example a Fragment or Activity, then this reference means that the long-running handler/loader/task will hold a reference to the activity which prevents it from getting garbage collected. Similarly, direct field references to activities and fragments from these longer running instances can cause leaks. ViewModel classes should never point to Views or non-application Contexts.
Maybe we can avoid this somehow?
Contributor guide
Assessment
This issue has not been assessed yet.