Damn. Completely lost track of this thread. Sorry about that. The GC should run automatically in a (javascript) timer (ie after your code isn’t running anymore and control returned to javascript).
Note that all native Island stuff has the same memory usage as on other platforms, what has a bit of overhead is dynamic dispatch, but there are tricks to avoid that. One example is above, instead of asking for data by iterating a js byte array , get all data over in 1 go.
Carlo, thank you for the clues. As I’ve mentioned before I made changes in my project and now I copy JS arrays instead of iterating through them. It improved the situation a little bit but still the amount of consumed memory is excessive. The same code run on .NET takes a tiny fraction of memory compared to WASM. I’ve tried to tinker with GC, hand control over back to JS but nothing seems to help. Would you please write me a piece of code that forces garbage collection and/or disposal of an object?
GC.Collect should force a GC ofc, but I’m now curious as to what you’re doing exactly that causes this. Can you show a hot path? So I can see whats going on.
Sorry for the long pause, unfortunately covid hit me few days ago and I wasn’t in a “working condition” up to now…
GC.Collect should force a GC
I don’t see a global GC object, only SimpleGC but it doesn’t have a Collect method. SimpleGCExt has it but what does the c argument mean? Is it the max generation to collect (as in .NET)? How to get the max generation value then?
but I’m now curious as to what you’re doing exactly that causes this. Can you show a hot path?
I’ve discarded all the code changes before the last post in hope that you’ll send me something that works .
@ck, this seems wrong; why, for WebAsse,nly/SimpleCG, is this an extension for Utilities, and not on SimpleGC? For BoehmGC (i.e. non-WebAssembly), it’s on the BoehmGC class itself — this seems inconsistent? Want me to fix this?
Is Utilities.Collect() the same as SimpleGCExt.Collect()? And what about the integer you need to pass to the method? What is it and what should be its value?
I believe the integer is the level of GC to run. It’s mainly there for consistency, on WebAssmebnly it is ignored, as there is only one level
I believe so. note that in 2687 this is moved to SimpleGC.Collect and/or the cross-platform compatible DefaultGC.Collect, which is a type alias to the platform’s default GC.
@mh & @ck, I started playing with GC outside of our big project and immediately found why it failed there. It seems that it’s way too aggresive and wipes things it shouldn’t. A test case: wasm_gc.zip (13.5 KB)
The GC problem I recently reported doesn’t appear if I don’t manually call Collect. This leads to a conclusion that GC never collects anything if not forced to and that’s where the huge memory consumption comes from. When is GC expected to automatically collect?
I think I’ve already asked it somewhere above - is there any way to force disposal of a particular object? I’ve tried this SimpleGC.ForceRelease(IntPtr(InternalCalls.Cast(_obj))) but it doesn’t seem to get the job done.
WASM debugging is broken in the latest Elements preview (11.0.0.2687) - when you try to start debugging it says it cannot find the WASM file. Also, after the installation the debugger reported missing coloader80.dll - I had to register it manually.