Memory Management (is GC collecting objects after navigation)?!
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Despot_Jakim
Posted On:   Sunday, September 6, 2009 04:55 AM

Is the following architecture in my J2ME application memory safe (will the garbage collector collect the left over view objects)? I have a relatively big J2ME application and I was thinking of a way to incorporate navigation logic. My current architecture constitutes of the following: I put a private Displayable previousDisplayable variable in every class that extends Displayable. When I construct them, I provide them with this previous displayble. And if I need to go back I just take this previousDisplayable and work with it. You can see this in the following code: Sample displayable: public class MyForm extends Form { private Displayable previousDisplayable; private Vector restOfData   More>>

Is the following architecture in my J2ME application memory safe (will the garbage collector collect the left over view objects)?


I have a relatively big J2ME application and I was thinking of a way to incorporate navigation logic. My current architecture constitutes of the following: I put a private Displayable previousDisplayable variable in every class that extends Displayable. When I construct them, I provide them with this previous displayble. And if I need to go back I just take this previousDisplayable and work with it. You can see this in the following code:


Sample displayable:

			
public class MyForm extends Form {

private Displayable previousDisplayable;
private Vector restOfData;

public MyForm(Displayable previousDisplayable, Vector restOfData) {
this.previousDisplayable = previousDisplayable;
this.restOfData = restOfData;
}
}



Sample command listener:
			
public class CommandListenerMyForm implements CommandListener {

private MyForm myForm;
private MyMidlet myMidlet;

public CommandListenerMyForm(MyForm myForm, MyMidlet myMidlet) {
this.myForm = myForm;
this.myMidlet = myMidlet;
}
}



Sample further navigation through CommandListener:
			
public void commandAction(Command command, Displayable d) {
if (command == NEXTY_TO_MY_FORM) {
MyForm form = new MyForm(previousDisplayable, restOfData);
CommandListenerSimptomForm clMyForm = new CommandListenerMyForm( form, getMidlet());
form.setCommandListener(clMyForm);
getMyMidlet().setCurrentDisplay(form);
}
}



Sample back navigation through CommandListener:
			
public void commandAction(Command command, Displayable d) {
if (command == BACK) {
getMyMidlet().setCurrentDisplay(myForm.getPreviousDisplayable());
}
}


Example: We have 3 screens, we went 1 -> 2 -> 3 and than went back to the 2nd one. I am really not sure if the GC will pick up the 3rd screen. I read at this place http://j2medevcorner.wordpress.com/2007/02/19/memory-management-in-j2me/ that the GC will pick up the object if "All references to an object are isolated. (Only A points to B and B to A so there is no way to access either anymore)". It makes sense, but in my case the 3rd screen has reference to the 2nd, but the 3rd one isn't referenced by any other object


My dilemma is what is going to happen when the space is running low? In other words, will the GC (garbage collector) collect the used Displayable objects or will they create a problem that the GC can't clean?


I would grateful if anyone can clarify this for me.


Kind Regards,

D.J.

   <<Less
About | Sitemap | Contact