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

Manually close ImageDecoder. #1109

Merged
merged 5 commits into from
Jan 27, 2022
Merged

Conversation

colinrtwhite
Copy link
Member

Fixes #1107.

ImageDecoder's source says we shouldn't call this method manually, but it looks like it isn't cleaned up unless it's called manually.

@leandroBorgesFerreira
Copy link
Contributor

leandroBorgesFerreira commented Jan 25, 2022

I still get the problem if I enable strictMode. But one thing I notice is that if SVG is the first page instead of the third, it stops breaking. So if I change:

val assetType: MutableStateFlow<AssetType> = MutableStateFlow(AssetType.SVG)

In MainViewModel in the main branch, the leak doesn't happen anymore... you need to change the pages in the ViewPager and then the problem starts to happen

@colinrtwhite
Copy link
Member Author

@leandroBorgesFerreira With the same stack trace? I think changing the initial page to SVG likely only masks the exception. Unfortunately I'm not sure what else can be done as Coil doesn't have access to the input stream allocated by ImageDecoder.FileSource.

@colinrtwhite
Copy link
Member Author

Going to merge this in as calling ImageDecoder.close should close the input stream according to the source.

@colinrtwhite colinrtwhite merged commit 014cc3f into main Jan 27, 2022
@colinrtwhite colinrtwhite deleted the colin/image_decoder_memory_leak branch January 27, 2022 00:53
colinrtwhite added a commit that referenced this pull request Oct 5, 2022
* Fixing resource leak in gifs

* Removing unnecessary use call

* Manually close ImageDecoder.

* Remove use.

* Refactor.

Co-authored-by: Leandro Borges Ferreira <lehen01@gmail.com>
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

Successfully merging this pull request may close these issues.

Memory leak in ImageDecoderDecoder for Gifs
2 participants