标签:
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; } }
标签:
原文地址:http://www.cnblogs.com/baron89/p/4579987.html