fix: Force finalizers to explore the graph of objects #277
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First, this patch provides new
Close
methods on some “top types”(
Store
,Module
,Instance
etc.). TheClose
methods areredundant 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 attachedto the object.
Note that runtime finalizers call the
Close
method if defined on thecurrent object.
Second, this patch forces the destructors (now the
Close
methods) todestruct 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 theirrespective 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 objectswere 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
mapfield. Before this patch, only the
_inner
C pointer was freed, butnot the map. I have no idea why the map wasn't collected by the Go
GC.
Running the script written by @prep in
#262 shows that there is
no more memory leaks.
Fix #262.
Fix #269.