单实例的类对象使用后,如何释放?

中才德创 中才德创 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
有个需求,在适当的时候,弹出一个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;
}
}
...全文
评论 9
收藏 已收藏
分享
返回顶部
中才德创
Java SE 62,621 成员 307,251 内容