内存泄露情况

1.单例,成员变量有Context(如果这个Context是Activity的话就会内存泄露了),因为instance是静态的,持有context的引用

 

public class Singleton{
    public static Singleton instance;
    public Context context;
    public static Singleton getInstance(Context context){
        if(instance == null){
            instance = new Singleton();
        }        
        instance.context = context;//正确的是这里context.getApplicationContext();
        return instance;
    }
}

 

posted @ 2015-06-16 10:00  BaronZ  阅读(232)  评论(0编辑  收藏  举报