-
Notifications
You must be signed in to change notification settings - Fork 675
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix memory leak if request is started on detached view. (#518)
* Fix memory leak if request is started on detached view. * Fix tests. * Docs. * Add regression test.
- Loading branch information
1 parent
1c48817
commit ac63a3b
Showing
13 changed files
with
132 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
coil-base/src/androidTest/java/coil/util/AndroidTestFunctions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package coil.util | ||
|
||
import android.app.Activity | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.test.core.app.ActivityScenario | ||
import androidx.test.core.app.launchActivity | ||
import androidx.test.ext.junit.rules.ActivityScenarioRule | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.runBlocking | ||
|
||
/** Launch [TestActivity] and invoke [block]. */ | ||
fun withTestActivity(block: (TestActivity) -> Unit) { | ||
launchActivity<TestActivity>().use { scenario -> | ||
scenario.moveToState(Lifecycle.State.RESUMED) | ||
scenario.onActivity(block) | ||
} | ||
} | ||
|
||
/** | ||
* Get a reference to the [ActivityScenario]'s [Activity]. | ||
* | ||
* NOTE: [ActivityScenario.onActivity] explicitly recommends against holding a | ||
* reference to the [Activity] outside of its scope. However, it should be safe | ||
* as long we use [ActivityScenarioRule]. | ||
*/ | ||
val <T : Activity> ActivityScenario<T>.activity: T | ||
get() { | ||
lateinit var activity: T | ||
runBlocking(Dispatchers.Main.immediate) { | ||
// onActivity is executed synchronously when called from the main thread. | ||
onActivity { activity = it } | ||
} | ||
return activity | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package coil.util | ||
|
||
import android.widget.ImageView | ||
import androidx.appcompat.app.AppCompatActivity | ||
import coil.base.test.R | ||
|
||
class TestActivity : AppCompatActivity(R.layout.ic_test_activity) { | ||
|
||
val imageView: ImageView by lazy { findViewById(R.id.image) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<FrameLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<ImageView | ||
android:id="@+id/image" | ||
android:layout_width="100px" | ||
android:layout_height="100px" | ||
android:layout_gravity="center" /> | ||
</FrameLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<style name="Theme.TestActivity" parent="@style/Theme.MaterialComponents.Light"> | ||
<item name="colorPrimary">#FF0000</item> | ||
<item name="colorPrimary">#FFFFFF</item> | ||
</style> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
sdk=29 | ||
sdk=28 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
sdk=29 | ||
sdk=28 |