Most appropriate sub-area of p5.js?
- Accessibility
- Color
- Core/Environment/Rendering
- Data
- DOM
- Events
- Image
- IO
- Math
- Typography
- Utilities
- WebGL
- WebGPU
- p5.strands
- Build process
- Unit testing
- Internationalization
- Friendly errors
- Other (specify if possible)
p5.js version
v2.3.1
Web browser and version
Firefox 153.0.1
Operating system
Fedora Linux 44 (Workstation Edition)
Steps to reproduce this
- Create multiple p5 instances.
- Each instance registers an instance-specific remove lifecycle hook.
- Call remove() on the instances.
- Check the length of p5.lifecycleHooks.remove.
For example:
test('remove hooks accumulate after instances are removed', async function () {
const before = p5.lifecycleHooks.remove.length;
let instance1;
let instance2;
await Promise.all([
new Promise(resolve => {
new p5(p => {
p.setup = () => {
instance1 = p;
resolve();
};
});
}),
new Promise(resolve => {
new p5(p => {
p.setup = () => {
instance2 = p;
resolve();
};
});
})
]);
assert.strictEqual(
p5.lifecycleHooks.remove.length,
before + 2
);
await instance1.remove();
await instance2.remove();
assert.strictEqual(
p5.lifecycleHooks.remove.length,
before + 2
);
});
The remove hooks are added to the global p5.lifecycleHooks.remove array when instances are created, but calling remove() does not remove those hook functions from the array. As more p5 instances are created and removed, the array therefore keeps growing.
Reactions are currently unavailable
Most appropriate sub-area of p5.js?
p5.js version
v2.3.1
Web browser and version
Firefox 153.0.1
Operating system
Fedora Linux 44 (Workstation Edition)
Steps to reproduce this
For example:
The remove hooks are added to the global p5.lifecycleHooks.remove array when instances are created, but calling remove() does not remove those hook functions from the array. As more p5 instances are created and removed, the array therefore keeps growing.