You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This means that if I have an object A that lives for a very long time (potentially even global), and I have many objects B that live for a short period of time, the pointer to what those objects hold will only be cleaned up when A is cleaned up, which might never happen. This will work, and will not be a problem in any use case where A doesn't live for too long (although it'll use more memory).
This reference dropping would need to work bilaterally. If B has a SharedReference on A, when B is dropped it needs to be dropped, and vice-versa. It seems that napi-rs misses half of that logic.
I tried implementing it myself, adding a Drop impl on SharedReference, but without success. Any implementation would also need a way to know if the pointer has been dropped already...or not, which seems like a hassle.
In the meantime, do you see a way for us to use lifetimes more efficiently? I might just declare my global in napi-exposed functions, and go from there. Thanks!
The text was updated successfully, but these errors were encountered:
I created a bit earlier this week the #1952 issue, which has been closed, but I'm still seeing a problem.
The "memory leak" naming was incorrect. Per my understanding, what happens is that if a struct B has a
SharedReference<A, ()>
, the pointer to the data that needs the reference (in that case,()
) is only cleaned up when thefinalize_callbacks
run for that said instance of A - see code here https://github.com/napi-rs/napi-rs/blob/main/crates/napi/src/bindgen_runtime/js_values/value_ref.rs#L137-L142This means that if I have an object A that lives for a very long time (potentially even global), and I have many objects B that live for a short period of time, the pointer to what those objects hold will only be cleaned up when A is cleaned up, which might never happen. This will work, and will not be a problem in any use case where A doesn't live for too long (although it'll use more memory).
This reference dropping would need to work bilaterally. If B has a
SharedReference
on A, when B is dropped it needs to be dropped, and vice-versa. It seems that napi-rs misses half of that logic.I tried implementing it myself, adding a
Drop
impl onSharedReference
, but without success. Any implementation would also need a way to know if the pointer has been dropped already...or not, which seems like a hassle.In the meantime, do you see a way for us to use lifetimes more efficiently? I might just declare my global in napi-exposed functions, and go from there. Thanks!
The text was updated successfully, but these errors were encountered: