I just jumped on the forums to ask the same question!
If I am correct, whenever you "pop" a screen, the object is no longer used, so the JVM will preform garbage collection on it (eventually).
I have tried something similar to the following, but not sure how "thread-safe" it is. (I'm just learning java, so I'm not an expert in thread-safety yet)
PHP Code:
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;
public class MyScreen extends MainScreen
{
private static MyScreen _singleInstance = null;
public MyScreen()
{
super();
// Add Components / Fields Here!
synchronized(this)
{
_singleInstance = this;
}
}
public static MyScreen getMyScreen()
{
if(_singleInstance == null)
{
_singleInstance = new MyScreen();
}
return _singleInstance;
}
}
Then replace:
PHP Code:
UiApplication.getUiApplication().pushScreen(new MyScreen());
with:
PHP Code:
UiApplication.getUiApplication().pushScreen(getMyScreen());
Doing this ensures that you are not constantly creating / destroying screens that do not change.
So, I hope I kind-of answered your question. The JVM takes care of garbage collection on the "pop"ed screens. But you are taking a performance hit by constantly creating and destroying something that may not change frequently.
Anyone have other tips on this?