internal/atlas: images were not collected by GC

This commit is contained in:
Hajime Hoshi 2023-11-04 04:37:40 +09:00
parent 95f7204035
commit ba93794a72
2 changed files with 4 additions and 4 deletions

View File

@ -624,11 +624,11 @@ func (i *Image) allocate(forbiddenBackends []*backend, asSource bool) {
panic("atlas: the image is already allocated") panic("atlas: the image is already allocated")
} }
runtime.SetFinalizer(i, func(img *Image) { runtime.SetFinalizer(i, func(image *Image) {
// A function from finalizer must not be blocked, but disposing operation can be blocked. // A function from finalizer must not be blocked, but disposing operation can be blocked.
// Defer this operation until it becomes safe. (#913) // Defer this operation until it becomes safe. (#913)
appendDeferred(func() { appendDeferred(func() {
i.deallocate() image.deallocate()
runtime.SetFinalizer(i, nil) runtime.SetFinalizer(i, nil)
}) })
}) })

View File

@ -38,11 +38,11 @@ func (s *Shader) ensureShader() *restorable.Shader {
return s.shader return s.shader
} }
s.shader = restorable.NewShader(s.ir) s.shader = restorable.NewShader(s.ir)
runtime.SetFinalizer(s, func(s *Shader) { runtime.SetFinalizer(s, func(shader *Shader) {
// A function from finalizer must not be blocked, but disposing operation can be blocked. // A function from finalizer must not be blocked, but disposing operation can be blocked.
// Defer this operation until it becomes safe. (#913) // Defer this operation until it becomes safe. (#913)
appendDeferred(func() { appendDeferred(func() {
s.deallocate() shader.deallocate()
}) })
}) })
return s.shader return s.shader