Android/Kotlin
안드로이드 스튜디오 Kotlin Memory Leak Warning("StaticFieldLeak")
금님은님아부지
2021. 2. 16. 12:41
728x90
- Android Studio (1.4 이상 plugin 설치) 에서 Kotlin Object Class 에 대해서 field 에 Context 를 선언할 경우 Warning 에러가 발생한다.
- Error Message
Do not place Android context classes in static fields (static reference to AppContext which has field activityContext pointing to Context); this is a memory leak
- 해결 방법
1. @SuppressLint("StaticFieldLeak") Annotation 추가한다.
2. context 를 Object class 에 넘겨주는 대신 Application Context 를 가져와서 참조하도록 처리 한다.
728x90