From 1d01779b2e58f898689e84ce20a9c9ae183a14fe Mon Sep 17 00:00:00 2001 From: Austin Wise Date: Thu, 5 Dec 2019 18:58:09 -0800 Subject: [PATCH] Root bindings so the delegate in FunctionBinding is not GCed. --- crates/misc/dotnet/src/Instance.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/misc/dotnet/src/Instance.cs b/crates/misc/dotnet/src/Instance.cs index c145d2be83..86f0b3f825 100644 --- a/crates/misc/dotnet/src/Instance.cs +++ b/crates/misc/dotnet/src/Instance.cs @@ -17,8 +17,10 @@ namespace Wasmtime Host = host; Module = module; - var bindings = host.GetImportBindings(module); - var handles = bindings.Select(b => b.Bind(module.Store, host)).ToList(); + //Save the bindings to root the objects. + //Otherwise the GC may collect the delegates from ExternFunction for example. + _bindings = host.GetImportBindings(module); + var handles = _bindings.Select(b => b.Bind(module.Store, host)).ToList(); unsafe { @@ -141,5 +143,6 @@ namespace Wasmtime private Interop.wasm_extern_vec_t _externs; private Dictionary _functions; private Dictionary _globals; + private List _bindings; } }