Skip to content

Commit aff2918

Browse files
authored
Fix growing memory on repeated Instance() invocation (#130)
* Fix: memory growing on repeated Instance() call * rm accidental trunk files * Add instantiated mod close on single mod cleanup() * Chg to delete instance for fn chaining * ci linter fix
1 parent 2e3d8fc commit aff2918

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

module.go

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ func (m *module[T]) register(function *function[T]) {
155155
func (m *module[T]) cleanup() {
156156
m.function = nil
157157
m.template.runtime.activeModulesMu.Lock()
158+
// m.instantiatedModule.CloseWithExitCode(m.template.runtime.config.context, 0)
158159
delete(m.template.runtime.activeModules, m.instantiatedModule.Name())
159160
m.template.runtime.activeModulesMu.Unlock()
160161
}

scale.go

+9
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ func (r *Scale[T]) Instance(next ...Next[T]) (*Instance[T], error) {
7070
return newInstance(r.config.context, r, next...)
7171
}
7272

73+
func (r *Scale[T]) Clear() {
74+
for key := range r.activeModules {
75+
r.activeModules[key].instantiatedModule.CloseWithExitCode(r.config.context, 0)
76+
delete(r.activeModules, key)
77+
}
78+
79+
r.activeModules = make(map[string]*module[T])
80+
}
81+
7382
// Reset any extensions between executions.
7483
func (r *Scale[T]) resetExtensions() {
7584
for _, ext := range r.config.extensions {

0 commit comments

Comments
 (0)