wasm4 icon indicating copy to clipboard operation
wasm4 copied to clipboard

Make R reset the cart in native runtime

Open desttinghim opened this issue 3 years ago • 5 comments

Closes #503

desttinghim avatar Aug 23 '22 17:08 desttinghim

I think this has a memory leak, w4_runtimeInit and w4_wasmLoadModule aren't currently designed to be called multiple times.

aduros avatar Sep 06 '22 00:09 aduros

Oops, I didn't think to check for that. I'll investigate and fix it

desttinghim avatar Sep 06 '22 02:09 desttinghim

I ran valgrind on this branch and on main, and I don't see any difference in the output. I think the existing memory is being re-used, and nothing is being allocated on reset. Let me know if I'm missing something obvious

desttinghim avatar Sep 06 '22 06:09 desttinghim

It's possible that the memory is reused, but that might be undefined behavior. Also, having an explicit teardown method would make it easier to safely port to other wasm engines.

aduros avatar Sep 12 '22 03:09 aduros

w4_runtimeInit looks like it can be called again no problem - it clears all the memory to zero and resets everything to default. w4_wasmLoadModule sets up the actual runtime, which doesn't need to be repeated, and probably shouldn't be either. The memory just needs to zeroed, and then the start function needs to be called if I understand correctly.

desttinghim avatar Oct 05 '22 06:10 desttinghim