Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compose memory #5226

Closed
CedrickFlocon opened this issue Jul 31, 2023 · 1 comment
Closed

Compose memory #5226

CedrickFlocon opened this issue Jul 31, 2023 · 1 comment

Comments

@CedrickFlocon
Copy link

Glide Version:
compose:1.0.0-alpha.3

Device/Android Version:
API 31

Issue details / Repro steps / Use case background:
When updating GlideImage model, previous bitmap is kept in memory.

class MainActivity : ComponentActivity() {

    @OptIn(ExperimentalGlideComposeApi::class)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val randomImage = { "https://static-a.imgix.net/starfish.png?w=${Random.nextInt(500, 1000)}" }

        setContent {
            var url by remember { mutableStateOf(randomImage()) }

            GlideImage(
                model = url,
                contentDescription = ""
            )

            LaunchedEffect(Unit) {
                flow {
                    while (true) {
                        delay(1000)
                        emit(randomImage())
                    }
                }.collect { url = it }
            }
        }
    }
}

Screenshot 2023-07-31 at 10 39 14

Screenshot 2023-07-31 at 10 40 19

@CedrickFlocon
Copy link
Author

CedrickFlocon commented Aug 1, 2023

I am closing this issue since I am not able to reproduce the issue with 1.0.0-alpha.4-SNAPSHOT.
This PR #5062 fixed the issue.

On alpha3 updating the model cause the Painter to launch a new coroutine without canceling the previous one.
This means we will never clear the target awaitClose { requestManager.clear(target) }
Those coroutine will be cancel only when leaving the compose tree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant