Skip to content

Conversation

@ishigurobot
Copy link
Contributor

Thank you for this nice plugin!

I found a memory leak problem and it cause runtime crash on iPhone.
It happens when I repeat Instantiate and Destroy components (ex. Holistic solution) via my script.
In memory profiler, Texture2D was increasing and leaking,
image
and those textures seem to have been generated by TextureFrames.
image

After adding Destroy() in Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Experimental/TextureFrame.cs, it's fixed.

I confirmed about Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/Experimental/TextureFrame.cs, but I don't know how should I do about Assets/MediaPipeUnity/Samples/Common/Scripts/ImageSource/TextureFrame.cs.

This Pull Request is just for your information.

@ishigurobot ishigurobot changed the title Add MonoBehaviour.Destroy(_texture) to fix memory leak fix: Add MonoBehaviour.Destroy(_texture) to fix memory leak Feb 18, 2025
Copy link
Owner

@homuler homuler left a comment

Choose a reason for hiding this comment

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

Thanks!

@ishigurobot
Copy link
Contributor Author

ishigurobot commented Feb 18, 2025

Sorry, I found more implementations are needed, and I've just pushed it now.
Since release functions about _textureFramePool are never called in HolisticTrackingSolution.cs and MediaPipeVideoSolution.cs,
I have to implement Stop() function like FaceLandmarkerRunner.cs and call it manually from script at least.

public override void Stop()
{
base.Stop();
_textureFramePool?.Dispose();
_textureFramePool = null;
}

If you want to call Stop() automatically, you have to implement OnDestroy() somewhere else, I think.

@homuler homuler changed the title fix: Add MonoBehaviour.Destroy(_texture) to fix memory leak fix: Destroy textures to fix memory leak Feb 18, 2025
@homuler homuler merged commit ef8d2c0 into homuler:master Feb 18, 2025
@ishigurobot
Copy link
Contributor Author

Thank you so much!

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.

2 participants