First, this patch provides new Close methods on some “top types”
(Store, Module, Instance etc.). The Close methods are
redundant to the runtime finalizers, but they are useful to force to
destruct a specific type manually before the Go GC collect it.
Note that calling Close will remove the runtime finalizer attached
to the object.
Note that runtime finalizers call the Close method if defined on the
current object.
Second, this patch forces the destructors (now the Close methods) to
destruct the children attached to the current object. Let's see it in
details:
Module now has two new fields importTypes *importTypes and
exportTypes *exportTypes. The value is null, except if the
Imports or Exports methods are called. They will store their
respective results in their respective fields. The goal of this
change is twofold:
Avoiding computing the same import and export types multiple
times each time one of the method is called,
By holding a reference to the private importTypes and
exportTypes, Module can free them. Before that, the objects
were orphan and the garbage collector had difficulties to collect
them.
Instance now forces to free its Exports,
Exports now force to free all the items of its exports map
field. Before this patch, only the _inner C pointer was freed, but
not the map. I have no idea why the map wasn't collected by the Go
GC.
First, this patch provides new
Close
methods on some “top types” (Store
,Module
,Instance
etc.). TheClose
methods are redundant to the runtime finalizers, but they are useful to force to destruct a specific type manually before the Go GC collect it.Note that calling
Close
will remove the runtime finalizer attached to the object.Note that runtime finalizers call the
Close
method if defined on the current object.Second, this patch forces the destructors (now the
Close
methods) to destruct the children attached to the current object. Let's see it in details:Module
now has two new fieldsimportTypes *importTypes
andexportTypes *exportTypes
. The value is null, except if theImports
orExports
methods are called. They will store their respective results in their respective fields. The goal of this change is twofold:Avoiding computing the same import and export types multiple times each time one of the method is called,
By holding a reference to the private
importTypes
andexportTypes
,Module
can free them. Before that, the objects were orphan and the garbage collector had difficulties to collect them.Instance
now forces to free itsExports
,Exports
now force to free all the items of itsexports
map field. Before this patch, only the_inner
C pointer was freed, but not the map. I have no idea why the map wasn't collected by the Go GC.Running the script written by @prep in https://github.com/wasmerio/wasmer-go/issues/262 shows that there is no more memory leaks.
Fix #262. Fix #269.