Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

Commit

Permalink
#33
Browse files Browse the repository at this point in the history
Fix the memory leaks when adapter doesn't reuse convertView
  • Loading branch information
openaphid committed Dec 27, 2012
1 parent 7d33e75 commit 8f9c1ef
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class FlipViewController extends AdapterView<Adapter> {
public static final int ORIENTATION_VERTICAL = 0;
public static final int ORIENTATION_HORIZONTAL = 1;

private static final int MAX_RELEASED_VIEW_SIZE = 4;

public static interface ViewFlipListener {
void onViewFlipped(View view, int position);
}
Expand Down Expand Up @@ -368,7 +370,12 @@ private void releaseViews() {
private void releaseView(View view) {
Assert.assertNotNull(view);
detachViewFromParent(view);
releasedViews.add(view);
addReleasedView(view);
}

private void addReleasedView(View view) {
if (releasedViews.size() < MAX_RELEASED_VIEW_SIZE)
releasedViews.add(view);
}

private View viewFromAdapter(int position, boolean addToTop) {
Expand All @@ -377,7 +384,7 @@ private View viewFromAdapter(int position, boolean addToTop) {
View releasedView = releasedViews.isEmpty() ? null : releasedViews.removeFirst();
View view = adapter.getView(position, releasedView, this);
if (view != releasedView)
releasedViews.add(releasedView);
addReleasedView(releasedView);

setupAdapterView(view, addToTop, view == releasedView);
return view;
Expand Down

0 comments on commit 8f9c1ef

Please sign in to comment.