Skip to content

Commit

Permalink
Fix growing memory on repeated Instance() invocation (#130)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dphilla authored Mar 8, 2024
1 parent 2e3d8fc commit aff2918
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions module.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func (m *module[T]) register(function *function[T]) {
func (m *module[T]) cleanup() {
m.function = nil
m.template.runtime.activeModulesMu.Lock()
// m.instantiatedModule.CloseWithExitCode(m.template.runtime.config.context, 0)
delete(m.template.runtime.activeModules, m.instantiatedModule.Name())
m.template.runtime.activeModulesMu.Unlock()
}
Expand Down
9 changes: 9 additions & 0 deletions scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ func (r *Scale[T]) Instance(next ...Next[T]) (*Instance[T], error) {
return newInstance(r.config.context, r, next...)
}

func (r *Scale[T]) Clear() {
for key := range r.activeModules {
r.activeModules[key].instantiatedModule.CloseWithExitCode(r.config.context, 0)
delete(r.activeModules, key)
}

r.activeModules = make(map[string]*module[T])
}

// Reset any extensions between executions.
func (r *Scale[T]) resetExtensions() {
for _, ext := range r.config.extensions {
Expand Down

0 comments on commit aff2918

Please sign in to comment.