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

c#: Update the allocation clean up code to avoid using closure which will allocate on the heap

Open jsturtevant opened this issue 1 year ago • 1 comments

Also note that cleanups.Add(()=> NativeMemory.AlignedFree({address})); will allocate closure.

Agree. I would consider handling this in a stack allocated struct that implements IDisposable or a ref struct with a Dispose() method. Note that Roslyn allows a ref struct with a Dispose(), not implementing IDisposable, to be used in a using statement.

Originally posted by @AaronRobinsonMSFT in #1012

jsturtevant avatar Jan 24 '25 00:01 jsturtevant

for some more possible design options: https://github.com/bytecodealliance/wit-bindgen/pull/1145#discussion_r1937031162

jsturtevant avatar Jan 31 '25 17:01 jsturtevant