question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hey,

I’m using RecoilJS to store references to WebAssembly values. These values must be manually freed by calling a .free() method on the reference in order to avoid memory leaks[1]. As far as I can tell, there’s currently no way to reliably call a destructor on a Recoil value[2].

My current approach is to define a selector wrapper around an atom with a set function that frees the previous value of the atom. However, when the Recoil root is unmounted, the set function isn’t invoked, and thus the values are leaked. Furthermore, I’m noticing race conditions during updates. I reckon it might be due to Recoil yielding control to the event loop between the time a value is set and the time React re-renders components with that value. During that time, it’s possible a component effect will try to use the previous recoil value, since freed. This can happen in a requestAnimationFrame callback.

It’d be nice to be able to define a destructor callback for atom values that gets called once the RecoilRoot tree has updated with the new value, or once the RecoilRoot that held that value has unmounted.

[1] https://rustwasm.github.io/wasm-bindgen/contributing/design/exporting-rust-struct.html [2] I’m aware WeakRef somewhat fixes this issue, but it isn’t available in Safari (yet?).

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
drarmstrcommented, Aug 24, 2020

Hmm, yeah, freeing previous value on set also could be unsafe with React Concurrent Mode, which may still be rendering part of the tree using the previous value.

We’re looking at memory management to free up resources when atoms are no longer used, but this is a slightly different situation where you care about specific atom values no longer being used. (cc @davidmccabe )

0reactions
alexkirszcommented, Nov 21, 2020

It looks like Atom Effects (experimental) would be a great solution to this problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Atom Heart Brother - song and lyrics by The Destructors - Spotify
Listen to Atom Heart Brother on Spotify. The Destructors · Song · 2012.
Read more >
Ozone Destructors
The Ozone Destruct technology safely destroys dangerous off-gassing ozone when making ozonated water or other products. Our QD-Ozone Destruct Series ...
Read more >
Atom Heart Brother - The Destructors - Amazon.com
Check out Atom Heart Brother by The Destructors on Amazon Music. Stream ad-free or purchase CD's and MP3s now on Amazon.com.
Read more >
Atom Destructor - YouTube
AboutPressCopyrightContact usCreatorsAdvertiseDevelopersTermsPrivacyPolicy & SafetyHow YouTube worksTest new features. © 2022 Google LLC ...
Read more >
Atomic Destructor - Christopher David Schmidt - Shazam
Listen to Atomic Destructor by Christopher David Schmidt, 14 Shazams.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found