wasm-bindgen icon indicating copy to clipboard operation
wasm-bindgen copied to clipboard

Is it necessary to call `free()` for js class binding instances?

Open rouzwelt opened this issue 10 months ago • 1 comments

Summary

All js class bindings come with a free() method, which frees up the memory allocated for them when they are instantiated, let's say there is a loop on js which inside that class binding is instantiated, does some other stuff and just then WITHOUT calling free() we go to next iteration, would this cause memory leak and those instances on each iteration persist on memory? or would they automatically end up in js gc and go out of scope themselves?

for (;;) {
  const bindingClassInstance = new BindingClass();
  // do something and NOT call free() on above instance
}

rouzwelt avatar Jan 17 '25 18:01 rouzwelt

It will be automatically garbage collected at some point, as long as your JS runtime supports FinalizationRegistry.

aqrln avatar Mar 01 '25 14:03 aqrln