역시나 아래 참고 싸이트를 번역한수준밖에는 안됩니다 ^^;;

 

보통 타이머를 사용하면

MainActivity에서, onCreate 부분에서 startTimer()를 호출하게 됩니다.

그러면 타이머 클래스는, 주기를 가지고 일정주기동안 계속해서 실행하게 됩니다.

 

Activity가 destroy가 호출되었지만 Activity내에서 타이머가 살아있게되면, 결국 Activity는 소멸되지못하고

Leak 이발생하게 됩니다.

 

어떻게 Memory Leak 을 막을 수 있을까요?

 

 

1. 액티비티가 종료되는 onDestory() 에서 cancerTimer() 와 같은, 타이머 종료호출 메서드를 call하여, 타이머를 종료시키고 그로인해, Activity의 reference가 잡히는것을 해지할 수 있습니다.

 

 

 

 

 

참고

https://android.jlelse.eu/9-ways-to-avoid-memory-leaks-in-android-b6d81648e35e

 

9 ways to avoid memory leaks in Android

I have been an android developer for quite some time now. And I realised that most of that time, I tend to spend on adding new features to…

android.jlelse.eu

 

+ Recent posts