I simple question but maybe a complex content. For example, I have this classes:
- ActivityA.class
- ActivityB.class
- ActivityC.class
- Singleton.class
Singleton is a singleton class pattern, for example:
public class Singleton {
static Singleton instance = new Singleton();
private Singleton();
List<HeavyObject> listaObjects;
}
I use this Singleton in any context (Activity).
My question is: Can Android release this class in any moment without release the current Activity? i.e., I’m watching Activity B, can Android destroy (release) my class Singleton or are the classes only unloaded when all the app is released?
Or maybe when an Activity is destroyed, because the classes are in the context of the Activities?
If there are no outstanding references to Singleton, as in any references are null, the garbage collection mechanism will destroy it once it does its rounds. This means that it will most likely be destroyed but not instantaneously once all references are null.
However, if even one Activity is using Singleton, it won’t be released unless that Activity is destroyed