My application makes hundred new Connection requests a day and parses json responce. But I've realized that it doesn't free the memory after each request.Though using system.gc() it stores the ConnectionRequest instance and instance of my class for parsing json responce. I guess at the end it causes system out of memory error.
here is some code:
protected boolean onMainFormCommand54(){
//LevakandRestService similar to GoogleRestService
final LevakandRestService r =new LevakandRestService();
r.RequestUBalance(balance);
final Progress p = new Progress(Globals.Loading, r);
p.showPacked(BorderLayout.CENTER, false);
p.setDisposeOnCompletion(true);
r.addResponseListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
p.dispose();
Dialog.show(Globals.Info, "Balance:" +balance.getBalance(),Globals.OK, "");
}
});
NetworkManager.getInstance().addToQueueAndWait(r);
System.gc();
return val;
}
I've tried using WeakReference but it doesn't helped.
protected boolean onMainFormCommand54() {//Balance of user
boolean val = super.onMainFormCommand54();
Balance balance1 = new Balance();
WeakReference wrb = new WeakReference(balance1);
final Balance balance =(Balance)wrb.get();
LevakandRestService r1 = new LevakandRestService();
WeakReference wr = new WeakReference(r1);
final LevakandRestService r =(LevakandRestService)wr.get();
r.RequestUBalance(balance);
final Progress p = new Progress(Globals.Loading, r);
p.showPacked(BorderLayout.CENTER, false);
p.setDisposeOnCompletion(true);
r.addResponseListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
p.dispose();
Dialog.show(Globals.Info, "Balance:" +balance.getBalance(),Globals.OK, "");
}
});
NetworkManager.getInstance().addToQueueAndWait(r);
r1=null;
balance1 = null;
System.gc();
return val;
}