Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

C# WASM JSImport callbacks

$
0
0

I'm using the JSImport feature for calling JavaScript from Blazor. It works fine, but I'm struggeling to understand the lifetime of callbacks.

For example I can add a callback/listener like this:

[JSImport("addListener", ModuleName)]public static partial void AddListener([JSMarshalAs<JSType.Function<JSType.Object>>] Action<JSObject> callback);

Which works just fine, but what is the lifetime of 'callback' on both the .NET and JavaScript sides? Am I causing memory leaks if I do not explicitly dispose something?

The documentation says: (Link)

You can pass Action/Func callbacks as parameters, which aremarshalled as callable JS functions. You can pass both JS and managedobject references, and they are marshaled as proxy objects, keepingthe object alive across the boundary until the proxy is garbagecollected.

I don't understand what a "proxy object" is in this context. It is a .NET or JavaScript object?

When inspecting the created JavaScript function it seems to have a dispose() function, but that doesn't really match with "until the proxy is garbage collected". I'm a bit lost...


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>