Skip to content
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

Memory leak when leaving the canvas page #322

Open
mlhoutel opened this issue Jan 22, 2023 · 3 comments
Open

Memory leak when leaving the canvas page #322

mlhoutel opened this issue Jan 22, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@mlhoutel
Copy link

Describe the bug
When there is a p5 component on a page and we navigate to another page, the canvas does not seem to be cleaned up. When we return to the page, another canvas is instantiated. If we browse several pages each containing a canvas, the performance is greatly degraded.

To Reproduce
This issue can be demonstrated on the site of p5-svelte:

  1. Go to https://p5-svelte.netlify.app/
  2. Click on the "Docs" button at the top (to navigate to https://p5-svelte.netlify.app/docs/get-started)
  3. Click on the "p5-svelte" button to go back to the main page
  4. Repeat the step 2. and 3. several times

You should notice a decrease in the framerate of the main demo (the update of the fractal canopy become jerky).

This can be measured more accurately using the p5.frameRate() function.

With one of my sites in svelte-kit (ssr), I noticed an increase (invariant of the drawing process) of on average 10ms per frame (60fps, so 16ms => 26ms => 36ms...)

Expected behavior
One should be able to navigate between pages without performance impact. The drawing process should be cleared after leaving the page.

Screenshots
image
Chrome recorded performances on https://p5-svelte.netlify.app/, the green curve represents the DOM nodes that are still held in memory

Desktop

  • OS: Windows 11
  • Browser: Chrome (v109.0.5414.75), Firefox (v108.0.2)
  • Version: 3.1.2
@mlhoutel mlhoutel added the bug Something isn't working label Jan 22, 2023
@dominikbeveridge
Copy link

Hey there,

Just letting you know I have the same problem. Have you managed to find a fix for it?

Cheers,

@mlhoutel
Copy link
Author

Yes, I proposed a fix here, but I didn't get any feedback. The repo author seems to be away.

However, it's quite easy to implement this solution directly in your project (for instance).

@dominikbeveridge
Copy link

I implemented it directly in my project as per your link, and it works perfectly. Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants