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

Weak references fails to automatic garbage collect #3903

Closed
yisibl opened this issue Mar 26, 2024 · 4 comments
Closed

Weak references fails to automatic garbage collect #3903

yisibl opened this issue Mar 26, 2024 · 4 comments
Labels

Comments

@yisibl
Copy link

yisibl commented Mar 26, 2024

Summary

wasm-bindgen 2.9.1 has --weak-refs turned on by default, but I recompiled resvg-js to wasm to test it in Node.js and it still shows a constant increase in memory usage.

  const pngData = resvg.render()
  const pngBuffer = pngData.asPng()
  // pngData.free() // I had to add `.free()` here to memory leak.

The documentation for wasm-bindgen says:

Without weak references your JS integration may be susceptible to memory leaks in Rust, for example:
You could forget to call .free() on a JS object, leaving the Rust memory allocated.

Please help me see what went wrong.

See https://github.com/yisibl/repro-resvg-wasm-memory-leak

@Liamolucko
Copy link
Collaborator

This is a bug; somebody already noticed this and wrote a fix for it in #3743, but it never got finished.

We probably should've waited for this to be fixed before enabling weak references by default, but I'd forgotten about it... oops.

@yisibl
Copy link
Author

yisibl commented Mar 27, 2024

@Liamolucko There is another related issue #3854

@mizdra
Copy link

mizdra commented Apr 7, 2024

The cause of this memory leak is as described at yisibl/resvg-js#318 (comment). It contains both #3854 and #3917 issues.

I think we can close this issue in favor of the two issues.

What do you think? @yisibl

@daxpedda
Copy link
Collaborator

Closing in favor of #3854.

@daxpedda daxpedda closed this as not planned Won't fix, can't repro, duplicate, stale Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants