Skip to content

Commit

Permalink
Merge pull request #114 from joomcode/feature/add-gc-support
Browse files Browse the repository at this point in the history
Add GC support for `vips.ImageRef`
  • Loading branch information
tonimelisma authored Nov 2, 2020
2 parents 8645108 + 6d7d58d commit 0e5c309
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion vips/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"io"
"io/ioutil"
"runtime"
"sync"
"unsafe"
)
Expand Down Expand Up @@ -157,10 +158,14 @@ func newImageRef(vipsImage *C.VipsImage, format ImageType, buf []byte) *ImageRef
format: format,
buf: buf,
}

runtime.SetFinalizer(image, finalizeImage)
return image
}

func finalizeImage(ref *ImageRef) {
ref.Close()
}

// Close closes an image and frees internal memory associated with it
func (r *ImageRef) Close() {
r.lock.Lock()
Expand Down

0 comments on commit 0e5c309

Please sign in to comment.