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

fix: Dispose TextBoxComponent image cache properly #1579

Merged
merged 5 commits into from
Apr 27, 2022

Conversation

spydon
Copy link
Member

@spydon spydon commented Apr 26, 2022

Description

Since we didn't dispose of the Image object that was used as a cache in TextBoxComponent we had a memory leak.

Side note: I wonder if it is really worth using PictureRecorder in that class.

Checklist

  • The title of my PR starts with a Conventional Commit prefix (fix:, feat:, docs: etc).
  • I have read the Contributor Guide and followed the process outlined for submitting PRs.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • I have updated/added relevant examples in examples.

Breaking Change

  • No, this is not a breaking change.

Related Issues

Fixes: #1462

Copy link
Member

@erickzanardo erickzanardo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nit, but LGTM already

Co-authored-by: Erick <erickzanardoo@gmail.com>
@st-pasha
Copy link
Contributor

I think there's still a possibility of a leak here if redraw() is called multiple times in a row. Not sure how to test for this though.

I believe the following version of redraw would be more robust:

  Future<void> redraw() async {
    final newSize = _recomputeSize();
    final image = await _fullRenderAsImage(newSize);
    cache?.dispose();
    cache = image;
    size = newSize;
  }

@spydon spydon enabled auto-merge (squash) April 27, 2022 17:57
@spydon spydon merged commit c0e3257 into main Apr 27, 2022
@spydon spydon deleted the spydon.dispose-text-box-component-image branch April 27, 2022 18:09
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 problem
4 participants