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

thorvg: terminate engine properly. #101

Merged
merged 1 commit into from
Mar 19, 2024

Conversation

hermet
Copy link
Member

@hermet hermet commented Mar 18, 2024

ThorVG requires the engine's initialization and
termination functions to be called in pairs.

  • clear will be conducted by the thorvg
    internally when it's terminated.

@hermet hermet added the refactoring Code refactoring label Mar 18, 2024
@hermet hermet self-assigned this Mar 18, 2024
Copy link

changeset-bot bot commented Mar 18, 2024

⚠️ No Changeset found

Latest commit: a383cc0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

ThorVG requires the engine's initialization and
termination functions to be called in pairs.

+ clear will be conducted by the thorvg
internally when it's terminated.
@hermet hermet changed the title thorvg: removed unnecessary call. thorvg: terminate engine properly. Mar 18, 2024
@hermet
Copy link
Member Author

hermet commented Mar 18, 2024

Please verify the build your side.

@@ -154,8 +156,8 @@ impl Canvas {
impl Drop for Canvas {
fn drop(&mut self) {
unsafe {
tvg_canvas_clear(self.raw_canvas, true);
tvg_canvas_destroy(self.raw_canvas);
Copy link
Member

Choose a reason for hiding this comment

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

Would tvg_canvas_destroy free the pushed paints from memory ? or do we still to manually free it in this case ?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, if the canvas retains the paints, it will delete them.

@theashraf
Copy link
Member

@samuelOsborne, can you help test whether the dotlottie-ios mem leak issue has been resolved with this change ?

@samuelOsborne
Copy link
Member

@theashraf Theres been a reduction in the size of the leak which is great 🚀 theres still a small one of 160 bytes that seems to happen only happen once randomly when removing / remaking the dotLottie player that I can't track down it may be :

  • from the UNIFFI generated code
  • the actual ios framework code
  • rust / thorvg

image

@hermet
Copy link
Member Author

hermet commented Mar 19, 2024

@samuelOsborne, thanks, could you address the actual ThorVG API call sequence that leads to memory leaks?

@theashraf
Copy link
Member

@hermet there's a concern with our setup in the LottieRenderer struct. Right now, when we instantiate a new LottieRenderer, it creates ThorVG Picture and Shape objects. The problem is, we don't push these to the canvas straight away. so, when we load new animation data, the objects we made earlier aren't cleared out.

@samuelOsborne That's explain why the memory leak is detected on the first run of the player. I'm thinking this issue might be better handled in a separate PR. It looks like it could touch a lot of areas because we might need to change when we create the Picture and Shape to only do it when we actually load an animation. This would mean checking in all our functions if these objects exist before we do anything with them.

@theashraf theashraf merged commit 1c05a84 into LottieFiles:main Mar 19, 2024
1 check passed
@hermet hermet deleted the hermet/refactoring branch April 7, 2024 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Code refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants