How/when is a Handler garbage collected?

后端 未结 3 1256
野的像风
野的像风 2021-02-12 16:15

Inside a class of mine I have the following code:

mHandler = createHandler();

private Handler createHandler() {
    return new Handler() {
        public void h         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-12 17:05

    In my specific example since the Handler is an anonymous inner class it has an implicit reference to the enclosing Object and the whole hierarchy of objects that is pointed by it.

    You could reduce the impact of the potential leak to almost nothing by using a static nested class instead of an anonymous inner class.

提交回复
热议问题