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
- 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.
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
p5instances.removelifecycle hook.remove()on the instances.p5.lifecycleHooks.remove.For example:
The
removehooks are added to the globalp5.lifecycleHooks.removearray when instances are created, but callingremove()does not remove those hook functions from the array. As morep5instances are created and removed, the array therefore keeps growing.