diff --git a/examples/helloworld/greeting/greet_host.pb.go b/examples/helloworld/greeting/greet_host.pb.go index 6b93eb0..260de48 100644 --- a/examples/helloworld/greeting/greet_host.pb.go +++ b/examples/helloworld/greeting/greet_host.pb.go @@ -167,11 +167,6 @@ func (p *greeterPlugin) Greet(ctx context.Context, request *GreetRequest) (*Gree resSize &^= (1 << 31) } - // We don't need the memory after deserialization: make sure it is freed. - if resPtr != 0 { - defer p.free.Call(ctx, uint64(resPtr)) - } - // The pointer is a linear memory offset, which is where we write the name. bytes, ok := p.module.Memory().Read(resPtr, resSize) if !ok { diff --git a/examples/host-function-library/proto/greet_host.pb.go b/examples/host-function-library/proto/greet_host.pb.go index c007e36..bd14569 100644 --- a/examples/host-function-library/proto/greet_host.pb.go +++ b/examples/host-function-library/proto/greet_host.pb.go @@ -223,11 +223,6 @@ func (p *greeterPlugin) Greet(ctx context.Context, request *GreetRequest) (*Gree resSize &^= (1 << 31) } - // We don't need the memory after deserialization: make sure it is freed. - if resPtr != 0 { - defer p.free.Call(ctx, uint64(resPtr)) - } - // The pointer is a linear memory offset, which is where we write the name. bytes, ok := p.module.Memory().Read(resPtr, resSize) if !ok { diff --git a/examples/host-functions/greeting/greet_host.pb.go b/examples/host-functions/greeting/greet_host.pb.go index cf75fb9..e611ef2 100644 --- a/examples/host-functions/greeting/greet_host.pb.go +++ b/examples/host-functions/greeting/greet_host.pb.go @@ -259,11 +259,6 @@ func (p *greeterPlugin) Greet(ctx context.Context, request *GreetRequest) (*Gree resSize &^= (1 << 31) } - // We don't need the memory after deserialization: make sure it is freed. - if resPtr != 0 { - defer p.free.Call(ctx, uint64(resPtr)) - } - // The pointer is a linear memory offset, which is where we write the name. bytes, ok := p.module.Memory().Read(resPtr, resSize) if !ok { diff --git a/examples/known-types/known/known_host.pb.go b/examples/known-types/known/known_host.pb.go index 1052cbf..9de7376 100644 --- a/examples/known-types/known/known_host.pb.go +++ b/examples/known-types/known/known_host.pb.go @@ -167,11 +167,6 @@ func (p *wellKnownPlugin) Diff(ctx context.Context, request *DiffRequest) (*Diff resSize &^= (1 << 31) } - // We don't need the memory after deserialization: make sure it is freed. - if resPtr != 0 { - defer p.free.Call(ctx, uint64(resPtr)) - } - // The pointer is a linear memory offset, which is where we write the name. bytes, ok := p.module.Memory().Read(resPtr, resSize) if !ok { diff --git a/examples/wasi/cat/cat_host.pb.go b/examples/wasi/cat/cat_host.pb.go index e656f28..91952d9 100644 --- a/examples/wasi/cat/cat_host.pb.go +++ b/examples/wasi/cat/cat_host.pb.go @@ -167,11 +167,6 @@ func (p *fileCatPlugin) Cat(ctx context.Context, request *FileCatRequest) (*File resSize &^= (1 << 31) } - // We don't need the memory after deserialization: make sure it is freed. - if resPtr != 0 { - defer p.free.Call(ctx, uint64(resPtr)) - } - // The pointer is a linear memory offset, which is where we write the name. bytes, ok := p.module.Memory().Read(resPtr, resSize) if !ok { diff --git a/gen/host.go b/gen/host.go index 715a2f9..82217b4 100644 --- a/gen/host.go +++ b/gen/host.go @@ -355,11 +355,6 @@ func genPluginMethod(g *protogen.GeneratedFile, f *fileInfo, method *protogen.Me resSize &^= %s } - // We don't need the memory after deserialization: make sure it is freed. - if resPtr != 0 { - defer p.free.Call(ctx, uint64(resPtr)) - } - // The pointer is a linear memory offset, which is where we write the name. bytes, ok := p.module.Memory().Read(resPtr, resSize) if !ok { diff --git a/tests/fields/proto/fields_host.pb.go b/tests/fields/proto/fields_host.pb.go index 84f5c64..6582f24 100644 --- a/tests/fields/proto/fields_host.pb.go +++ b/tests/fields/proto/fields_host.pb.go @@ -180,11 +180,6 @@ func (p *fieldTestPlugin) Test(ctx context.Context, request *Request) (*Response resSize &^= (1 << 31) } - // We don't need the memory after deserialization: make sure it is freed. - if resPtr != 0 { - defer p.free.Call(ctx, uint64(resPtr)) - } - // The pointer is a linear memory offset, which is where we write the name. bytes, ok := p.module.Memory().Read(resPtr, resSize) if !ok { @@ -241,11 +236,6 @@ func (p *fieldTestPlugin) TestEmptyInput(ctx context.Context, request *emptypb.E resSize &^= (1 << 31) } - // We don't need the memory after deserialization: make sure it is freed. - if resPtr != 0 { - defer p.free.Call(ctx, uint64(resPtr)) - } - // The pointer is a linear memory offset, which is where we write the name. bytes, ok := p.module.Memory().Read(resPtr, resSize) if !ok { @@ -302,11 +292,6 @@ func (p *fieldTestPlugin) TestError(ctx context.Context, request *ErrorRequest) resSize &^= (1 << 31) } - // We don't need the memory after deserialization: make sure it is freed. - if resPtr != 0 { - defer p.free.Call(ctx, uint64(resPtr)) - } - // The pointer is a linear memory offset, which is where we write the name. bytes, ok := p.module.Memory().Read(resPtr, resSize) if !ok { diff --git a/tests/host-functions/proto/host_host.pb.go b/tests/host-functions/proto/host_host.pb.go index f1a9858..9feba02 100644 --- a/tests/host-functions/proto/host_host.pb.go +++ b/tests/host-functions/proto/host_host.pb.go @@ -223,11 +223,6 @@ func (p *greeterPlugin) Greet(ctx context.Context, request *GreetRequest) (*Gree resSize &^= (1 << 31) } - // We don't need the memory after deserialization: make sure it is freed. - if resPtr != 0 { - defer p.free.Call(ctx, uint64(resPtr)) - } - // The pointer is a linear memory offset, which is where we write the name. bytes, ok := p.module.Memory().Read(resPtr, resSize) if !ok { diff --git a/tests/import/proto/bar/bar_host.pb.go b/tests/import/proto/bar/bar_host.pb.go index ad194bf..59bbd66 100644 --- a/tests/import/proto/bar/bar_host.pb.go +++ b/tests/import/proto/bar/bar_host.pb.go @@ -167,11 +167,6 @@ func (p *barPlugin) Hello(ctx context.Context, request *Request) (*Reply, error) resSize &^= (1 << 31) } - // We don't need the memory after deserialization: make sure it is freed. - if resPtr != 0 { - defer p.free.Call(ctx, uint64(resPtr)) - } - // The pointer is a linear memory offset, which is where we write the name. bytes, ok := p.module.Memory().Read(resPtr, resSize) if !ok { diff --git a/tests/import/proto/foo/foo_host.pb.go b/tests/import/proto/foo/foo_host.pb.go index 51433f6..32ec4b0 100644 --- a/tests/import/proto/foo/foo_host.pb.go +++ b/tests/import/proto/foo/foo_host.pb.go @@ -168,11 +168,6 @@ func (p *fooPlugin) Hello(ctx context.Context, request *Request) (*bar.Reply, er resSize &^= (1 << 31) } - // We don't need the memory after deserialization: make sure it is freed. - if resPtr != 0 { - defer p.free.Call(ctx, uint64(resPtr)) - } - // The pointer is a linear memory offset, which is where we write the name. bytes, ok := p.module.Memory().Read(resPtr, resSize) if !ok { diff --git a/tests/well-known/proto/known_host.pb.go b/tests/well-known/proto/known_host.pb.go index f9811bb..bc90a68 100644 --- a/tests/well-known/proto/known_host.pb.go +++ b/tests/well-known/proto/known_host.pb.go @@ -168,11 +168,6 @@ func (p *knownTypesTestPlugin) Test(ctx context.Context, request *Request) (*Res resSize &^= (1 << 31) } - // We don't need the memory after deserialization: make sure it is freed. - if resPtr != 0 { - defer p.free.Call(ctx, uint64(resPtr)) - } - // The pointer is a linear memory offset, which is where we write the name. bytes, ok := p.module.Memory().Read(resPtr, resSize) if !ok { @@ -341,11 +336,6 @@ func (p *emptyTestPlugin) DoNothing(ctx context.Context, request *emptypb.Empty) resSize &^= (1 << 31) } - // We don't need the memory after deserialization: make sure it is freed. - if resPtr != 0 { - defer p.free.Call(ctx, uint64(resPtr)) - } - // The pointer is a linear memory offset, which is where we write the name. bytes, ok := p.module.Memory().Read(resPtr, resSize) if !ok { diff --git a/wasm/plugin.go b/wasm/plugin.go index 689b783..f2e31ce 100644 --- a/wasm/plugin.go +++ b/wasm/plugin.go @@ -5,6 +5,7 @@ package wasm import ( + "runtime" "unsafe" ) @@ -38,6 +39,9 @@ func Malloc(size uint32) uint32 { func Free(ptr uint32) { // Remove the slice from the allocations map so the GC can reclaim it later. delete(allocations, ptr) + + // Let GC run + runtime.Gosched() } func PtrToByte(ptr, size uint32) []byte {