Inspectopedia Help

Static Field Leaks

Static Field Leaks

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.

Issue id: StaticFieldLeak

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for Android 2023.3, Qodana for JVM 2023.3


Android, 2022.3.1 Beta 2

Last modified: 13 July 2023