陈宇凡:android Avoid Memory Leaks 内部类问题
来源:百度文库 编辑:九乡新闻网 时间:2024/05/19 23:10:29
An inner class holds a reference to the object instance that created it; thus, in the following: public class Outer { public class Inner { } Inner i = new Inner(); }
Outer o = new Outer; Outer.Inner oi = o.i; o = null; // o is still alive because oi references it oii has a hidden reference (the "outer this") to the enclosing class instance o. So long as somebody holds a reference to the Inner object, the reference to the outer object remains alive. If you mark the enclosing class or enclosing method as static, the inner class will be a static inner class, which holds no reference to the enclosing class (and also therefore lacks the ability to referencere fields and methods of the outer class). Event listeners were a common source of leaks (meaning, longer-lived objects than intended) in Swing code back in the day. Might try hunting around that way on Google--there used to be a great article on "four types of lapsed listeners" back then, that described all of this in more detail.
Outer o = new Outer; Outer.Inner oi = o.i; o = null; // o is still alive because oi references it oii has a hidden reference (the "outer this") to the enclosing class instance o. So long as somebody holds a reference to the Inner object, the reference to the outer object remains alive. If you mark the enclosing class or enclosing method as static, the inner class will be a static inner class, which holds no reference to the enclosing class (and also therefore lacks the ability to referencere fields and methods of the outer class). Event listeners were a common source of leaks (meaning, longer-lived objects than intended) in Swing code back in the day. Might try hunting around that way on Google--there used to be a great article on "four types of lapsed listeners" back then, that described all of this in more detail.
android Avoid Memory Leaks 内部类问题
领略Java内部类的“内部”
Memory
memory
Java学习总结之第十章 内部类
JAVA内部类的作用 - - JavaEye技术网站
Memory Lane
伊莲佩姬 《memory 》
Android源码编译遇到的问题
Android
android
Android
Lover's memory
Memory Improvement Techniques
关于MIUI搭配A2SD+问题!~! - HTC Leo|HD2 Android XDA ...
Android替换字体时需要注意的一些问题
Android 开发环境安装失败问题总结 win7下 ? 寻梦人
在Wiki Leaks内部--新书预览
Nuclear industry expects scrutiny after leaks !
China cracks down on economic data leaks
Failure to prevent oil leaks riles watchdog
六十秒内轻松解决 美容问题
response.write""引号内的语法问题
六十秒内轻松解决美容问题