我有一个单例,我想让它在 Application
的一生中保持 Activity 状态。 .
public final class KeepAlive extends Whatever {
private KeepAlive() {}
private static class Singleton {
private static final KeepAlive instance = new KeepAlive();
}
}
是Singleton.instance
被认为是强引用,这样它就不会被GC'ed?
更新: Android 使用自定义类加载器吗?是这样,它会卸载像 KeepAlive
这样的类吗?或Singleton
?
最佳答案
简短的回答 - 是的。一旦创建,就不会被垃圾回收。
关于java - Android 静态引用强吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26765109/