Skip to content

Commit

Permalink
Fix GifDrawable leaks in GifDrawableTest.
Browse files Browse the repository at this point in the history
  • Loading branch information
sjudd committed Dec 9, 2017
1 parent 7ab1621 commit 523562c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public void loadGif_withInterlacedTransparentGif_sizeOriginal_succeeds()
.submit()
.get();
assertThat(gifDrawable).isNotNull();
gifDrawable.stop();
}

@Test
Expand All @@ -82,7 +81,6 @@ public void loadGif_withInterlacedTransparentGif_downsampled_succeeds()
.submit(10, 10)
.get();
assertThat(gifDrawable).isNotNull();
gifDrawable.stop();
}

@Test
Expand All @@ -95,7 +93,6 @@ public void loadGif_withTransparentGif_sizeOriginal_succeeds()
.submit()
.get();
assertThat(gifDrawable).isNotNull();
gifDrawable.stop();
}

@Test
Expand All @@ -108,7 +105,6 @@ public void loadGif_withTransparentGif_downsampled_succeeds()
.submit(10, 10)
.get();
assertThat(gifDrawable).isNotNull();
gifDrawable.stop();
}

@Test
Expand All @@ -121,7 +117,6 @@ public void loadGif_withOpaqueGif_sizeOriginal_succeeds()
.submit()
.get();
assertThat(gifDrawable).isNotNull();
gifDrawable.stop();
}

@Test
Expand All @@ -134,7 +129,6 @@ public void loadGif_withOpaqueGif_downsampled_succeeds()
.submit(10, 10)
.get();
assertThat(gifDrawable).isNotNull();
gifDrawable.stop();
}

@Test
Expand All @@ -147,7 +141,6 @@ public void loadGif_withOpaqueInterlacedGif_sizeOriginal_succeeds()
.submit()
.get();
assertThat(gifDrawable).isNotNull();
gifDrawable.stop();
}

@Test
Expand All @@ -160,7 +153,6 @@ public void loadGif_withOpaqueInterlacedGif_downsampled_succeeds()
.submit(10, 10)
.get();
assertThat(gifDrawable).isNotNull();
gifDrawable.stop();
}

@Test
Expand Down Expand Up @@ -216,8 +208,8 @@ public void run() {
GifDrawable drawableFromView = (GifDrawable) imageView.getDrawable();
assertThat(drawableFromView.isRunning()).isTrue();

gifDrawable.stop();
drawableFromView.stop();
gifDrawable.stop();
}

@SuppressWarnings("deprecation")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.bumptech.glide.test;

import android.support.test.InstrumentationRegistry;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
Expand All @@ -18,6 +20,15 @@ public void evaluate() throws Throwable {
try {
base.evaluate();
} finally {
new ConcurrencyHelper().runOnMainThread(new Runnable() {
@Override
public void run() {
RequestManager requestManager =
Glide.with(InstrumentationRegistry.getTargetContext());
requestManager.onStop();
requestManager.onDestroy();
}
});
Glide.tearDown();
}
}
Expand Down
3 changes: 3 additions & 0 deletions library/src/main/java/com/bumptech/glide/Glide.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ public static synchronized void init(Context context, GlideBuilder builder) {
@VisibleForTesting
public static synchronized void tearDown() {
if (glide != null) {
glide.getContext()
.getApplicationContext()
.unregisterComponentCallbacks(glide);
glide.engine.shutdown();
}
glide = null;
Expand Down

0 comments on commit 523562c

Please sign in to comment.