Skip to content

fix: manual cleanup capability of text and memory #7700 #7890

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

uppathidev
Copy link

@uppathidev uppathidev commented Jun 8, 2025

Resolves #7700

Changes: FIX: manual cleanup capability of text and memory

Screenshots of the change:

PR Checklist

Copy link

welcome bot commented Jun 8, 2025

🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already. And be sure to add yourself to the list of contributors on the readme page!

@davepagurek
Copy link
Contributor

Hi @uppathidev! Currently we're only adding new features to p5 2.x, which is in the dev-2.0 branch. Do you think you could base your changes off of that branch and create a PR into it instead?

@@ -455,6 +455,15 @@ p5.Texture = class Texture {
}
};

// manual cleanup capability
p5.Texture.prototype.free = function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can just make this method directly in the texture class in this file rather than adding it to the prototype here.

@davepagurek
Copy link
Contributor

davepagurek commented Jun 11, 2025

Also, some general thoughts:

  • I think we maybe don't want to add methods directly onto things like a p5.Image, as they can actually be used on multiple renderers, and their textures will exist separately on each renderer. Instead, we likely want a method on p5.RendererGL that you call on a visual, like freeTexture(myImg) (similar to how freeGeometry works for p5.Geometry.)
  • When we remove text textures, this is currently what we do:

    p5.js/src/webgl/text.js

    Lines 809 to 813 in 3eae276

    const tex = this.textures.get(data);
    if (tex) {
    tex.remove();
    this.textures.delete(data);
    }
    This is probably all we need inside of a freeTexture method.

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.

Add a way to clean up image texture resources in WebGL
2 participants