I have a static singleton class that extends my User object:
public class TestSingleton extends User{
private static TestSingleton singletonInstance;
private TestSingleton() {
}
public static TestSingleton getObj() {
if (singletonInstance == null) {
singletonInstance = new TestSingleton();
}
return singletonInstance;
}
}
The purpose of the singleton is to avoid create new instance any time i want to use my User object in different activities:
TestSingleton test = new TestSingleton();
test.doSomthing();
And to write it on one line and create instance only one time in my app life cycle:
TestSingleton.getObj().doSomthing();
My question is:
Is this use of static Singleton create memory leak and hold reference to any activity I use the singleton?
Is it safe to use? or there is a better solution?