You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: aspnetcore/blazor/javascript-interop.md
+65-1Lines changed: 65 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -504,7 +504,9 @@ returnArrayAsyncJs: function () {
504
504
505
505
You can also call .NET instance methods from JavaScript. To invoke a .NET instance method from JavaScript:
506
506
507
-
* Pass the .NET instance to JavaScript by wrapping it in a `DotNetObjectReference` instance. The .NET instance is passed by reference to JavaScript.
507
+
* Pass the .NET instance by reference to JavaScript:
508
+
* Make a static call to `DotNetObjectReference.Create`.
509
+
* Wrap the instance in a `DotNetObjectReference` instance and call `Create` on the `DotNetObjectReference` instance. Dispose of `DotNetObjectReference` objects (an example appears later in this section).
508
510
* Invoke .NET instance methods on the instance using the `invokeMethod` or `invokeMethodAsync` functions. The .NET instance can also be passed as an argument when invoking other .NET methods from JavaScript.
509
511
510
512
> [!NOTE]
@@ -550,6 +552,68 @@ Console output in the browser's web developer tools:
550
552
Hello, Blazor!
551
553
```
552
554
555
+
To avoid a memory leak and allow garbage collection on a component that creates a `DotNetObjectReference`, dispose of the object in the class that created the `DotNetObjectReference` instance:
0 commit comments