processing / p5.js

p5.js is a client-side JS platform that empowers artists, designers, students, and anyone to learn to code and express themselves creatively on the web. It is based on the core principles of Processing. http://twitter.com/p5xjs —
http://p5js.org/
GNU Lesser General Public License v2.1
21.08k stars 3.22k forks source link

`p5.Framebuffer.remove()` doesn't remove some resources #7048

Closed nickmcintyre closed 1 month ago

nickmcintyre commented 1 month ago

Most appropriate sub-area of p5.js?

p5.js version

1.9.3

Web browser and version

Chrome 124.0.6367.208

Operating system

macOS 14.4.1

Steps to reproduce this

Steps:

  1. Call myBuffer.remove().
  2. Call print(myBuffer) or use myBuffer elsewhere.

Snippet:

function doubleClicked() {
  myBuffer.remove();

  // Should this be empty-ish?
  print(myBuffer);
}

Here's the sketch for reference.

Does myBuffer have to be nullified in order for its resources to be garbage collected? It seems like the only other reference is cleared here.

Maybe too in-the-weeds, but if there's another reference somewhere in the sketch, then the resources are never fully freed.

davepagurek commented 1 month ago

The method is only intended to remove its GPU resources, which have to be manually cleaned up. All JS resources will be garbage collected as long as nothing else refers to it. That means to fully remove a framebuffer and its CPU resources, you'd have to do:

myBuffer.remove()
myBuffer = undefined

That said, there isn't much stored on the CPU, so it's less of a concern than cleaning up the GPU bits, where it stores the texture data.

nickmcintyre commented 1 month ago

That makes sense; just made some edits in #7044 to reflect this.