Nikola
Nikola

Reputation: 109

Allocated memory keeps increasing

Allocated memory keeps increasing, didn't decreased for a 1mb... Looks like garbage collector has not been called at all.

I have main activity with tab layout and 4 fragments (like on instagram) and with a lot of bitmaps which I get from the server. Once I download data from internet, I use to save ArrayList of objects to be called if that fragment been called again. Example:

@Override
public void onPause() {
    super.onPause();

    if (itemsArray != null) {
        savedListState = new Bundle();
        savedListState.putSerializable("myKey", itemsArray);
    }
}
@Override
public void onResume() {
    super.onResume();

    if (savedListState != null) {
        customGridProfileAdapter = new CustomGridProfileAdapter(getActivity(), itemsArray);
        gridView.setAdapter(customGridProfileAdapter);
        savedListState = null;
    }
}

I'm not destroying views at all. I thought that was the problem, but looks like it's not, because when I switch between activities it still works the same way, even when I destroy views of activity that's being replaced. So what to do? Why garbage collector don't decrease allocated memory? And what should I do about holding already downloaded items?

Upvotes: 1

Views: 1019

Answers (1)

Uriel Frankel
Uriel Frankel

Reputation: 14612

You might have a memory leak in your app. To learn more about memory leaks watch this wonderful video. From my experience, every app that is large and uses other api's will suffer from this issue.

Upvotes: 1

Related Questions