Android AsyncTask - memory problem

Handling background tasks in Android is achieved by using a class called AsyncTask. I strongly suggest reading the Android Documentation on the topic, if you haven't already done so (AsyncTask). I wanted to synchronize data between the server and my app in background. The idea was to compare a list of local id's with the one on the server. In case of any new id's, another asynchronous task should get the detailed data for each id. The default mode of operation for async tasks is that they run concurrently. That way you define what you want and send it on it's way. When the data is retrieved, your listener is notified. It seems to be working well on emulator, as well as on device. But when you need to update a lot of details (causing lot of async task being run at the same time) you will run into memory problems, usually by way of " E/dalvikvm-heap(): Out of memory on a xyz-byte allocation.". Problems may occur really fast on devices with less memory. The simplest approach for tackling this problem was to make the tasks run one after the other, thus still mantining responsivenes of the main GUI thread.

Here is an example of AsyncTask:

public class Get extends AsyncTask<Integer, Void, List<Integer>> {
    private Callbacks mCallback;

    public Get(Context context){
        mCallback = callback;
    }

    @Override
    protected List<Integer> doInBackground(Integer... params) {
        if (params.length == 0)
            return new ArrayList<Integer>();

        //get some detail about first id
        {your code to get some data}

        //take out first id and return other ids
        List<Integer> ids = new ArrayList<Integer>(Arrays.asList(params));
        ids.remove(0);
        return ids;
    }

    @Override
    protected void onPostExecute(List<Integer> ids) {
        //notify callback
        mCallback.onGetCompleted(ids);
    }
}

Here is example of the listener:

 @Override
public void onGetCompleted(List<Integer> ids) {
    if (ids.size() == 0){
        //all ids are updated
    }

    //still need to update and call again async task
    new com.examplemyapp.Get(this)
            .execute(ids.toArray(new Integer[ids.size()]));
}

After spawning AsyncTasks sequentially there were no more memory problems, even on devices running with less than 512 MB RAM.