Skip to content

Commit 459d166

Browse files
committed
Fix GC Bug
1 parent 56ce347 commit 459d166

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/SharpWebview/SharpWebview.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<Owners>Gerrit 'Geaz' Gazic</Owners>
88
<Description>C# bindings for zserge/webview - Batteries included</Description>
99
<PackageId>SharpWebview</PackageId>
10-
<PackageVersion>0.5.3</PackageVersion>
10+
<PackageVersion>0.5.4</PackageVersion>
1111
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1212
<PackageProjectUrl>https://github.com/geaz/sharpWebview</PackageProjectUrl>
1313
</PropertyGroup>

src/SharpWebview/Webview.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
using System;
2-
using System.Diagnostics;
32
using Newtonsoft.Json;
43
using SharpWebview.Content;
4+
using System.Diagnostics;
5+
using System.Collections.Generic;
56

67
namespace SharpWebview
78
{
@@ -12,6 +13,8 @@ namespace SharpWebview
1213
public class Webview : IDisposable
1314
{
1415
private bool _disposed = false;
16+
private List<CallBackFunction> callbacks = new List<CallBackFunction>();
17+
1518
private readonly IntPtr _nativeWebview;
1619

1720
/// <summary>
@@ -93,7 +96,10 @@ public Webview Navigate(IWebviewContent webviewContent)
9396
/// <returns>The webview object for a fluent api.</returns>
9497
public Webview Bind(string name, Action<string, string> callback)
9598
{
96-
Bindings.webview_bind(_nativeWebview, name, (id, req, arg) => { callback(id, req); }, IntPtr.Zero);
99+
var callbackInstance = new CallBackFunction((id, req, arg) => { callback(id, req); });
100+
callbacks.Add(callbackInstance); // Pin the callback for the GC
101+
102+
Bindings.webview_bind(_nativeWebview, name, callbackInstance, IntPtr.Zero);
97103
return this;
98104
}
99105

0 commit comments

Comments
 (0)