单实例的类对象使用后,如何释放?
有个需求,在适当的时候,弹出一个Dialog,请求用户输入签名。
如果不使用单实例,只需要将mDlgSignElectron=null,就能够释放这个对象了。
使用单实例,防止弹出多个Dialog。但同时带来的一个问题,当用户输入签名退出Dialog,这个单实例的对象一直驻留在内存里,如何释放呢?
如果不使用单实例,只需要将mDlgSignElectron=null,就能够释放这个对象了。
使用单实例,防止弹出多个Dialog。但同时带来的一个问题,当用户输入签名退出Dialog,这个单实例的对象一直驻留在内存里,如何释放呢?
//调用
AvcSignElectronDialog mDlgSignElectron;
mDlgSignElectron = AvcSignElectronDialog.getInstance(LoginActivity.this, R.style.SignElectronDialogTheme);
mDlgSignElectron.show();
//单实例类
public class AvcSignElectronDialog extends Dialog {
private static AvcSignElectronDialog mSingleton = null;
public static synchronized AvcSignElectronDialog getInstance(Context context, int theme) {
if (mSingleton == null) {
mSingleton = new AvcSignElectronDialog(context, theme);
}
return mSingleton;
}
private AvcSignElectronDialog(Context context, int theme) {
super(context, theme);
this.mContext = context;
}
}
...全文
相关推荐
C#使用Mutex简单实现程序单实例运行的方法
主要介绍了C#使用Mutex简单实现程序单实例运行的方法,涉及C#实现单实例程序运行的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下
基于centos7的单实例openstack安装
基于centos7的单实例openstack安装,包括(网络模式为桥接网络), 有基本功能(如计算、网络、存储和仪表板)都安装在同一台机器上。这种安装方法也是概念验证(POC)的最佳方法。
WPF单实例应用程序-一次打开一个exe
基于 Microsoft.VisualBasic.dll
C#实现单实例应用功能
基于WPF实现C#单实例应用检测功能,只允许操作系统中存在一个应用实例
只有一个实例 单实例编程 vc 源码
只有一个实例 单实例编程 vc 源码 single instance


Java SE
