Update:
gc will only work after the final } , which means taht only after the entire for loop has completed will the gc garbage collection be running once. so, is there any programming patter that can be used here? kinda like a for loop but in the mean time also allow gc to run each iteration. I don't know if I'd made myself clear... I can live with the performance dropping caused by gc running each iteration.
I was using volley on a android project and I can't get a working solution.
basically I have a huge collection of stuff that I will send (thru http with volley lib) continuously. when I send 10 of them it's no problem, but if I do it continuously it will eventually eat up all the memory and the app get terminated because of the heat space it taken.
below is the demo code block
requestqueue = Common.getQueue();//it will get a normal requestqueue
for (int i = 0; i < waitinglist.size(); i++) {
synccopyreq.filedatas.add(Common.getDataFromWaitinglist(i));
Common.httpPostWithQueue( requestqueue,"tagfullcopy", httpEndPoint+"/sync/fullcopy", gson.toJson(synccopyreq), that, new Common.CallbackInterface() {
@Override
public void completed(String result)
{
Log.i("shawhu","ok done");
}
});
//this was added but it doesn't work unfortunately
//using System.gc() like so was not recommended and most of the time wont'be effective either, I knew that.
System.gc();
}
Please read this, I've tried the profiler, when the whole thing complete (like when dealing with 10 items) the memory usage will go down fine, but if I run it continuously, it won't. the memory usage just go up continuously and it will eventually break the app (terminated by the android system). How do I free memory in every iteration in the loop?
Please help me, thanks!!