Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is HandlerLeak?

Tags:

android

ADT's lint checker says:

This Handler class should be static or leaks might occur

What's the meaning of the leak handler?

like image 299
Johnny Avatar asked Aug 23 '12 03:08

Johnny


1 Answers

from http://tools.android.com/tips/lint-checks

HandlerLeak

Summary: Ensures that Handler classes do not hold on to a reference to an outer class

Priority: 4 / 10 Severity: Warning Category: Performance

In Android, Handler classes should be static or leaks might occur. Messages enqueued on the application thread's MessageQueue also retain their target Handler. If the Handler is an inner class, its outer class will be retained as well. To avoid leaking the outer class, declare the Handler as a static nested class with a WeakReference to its outer class.

like image 156
Johnny Avatar answered Oct 31 '22 18:10

Johnny