From 6d7d58d75a710fbe122ac14d09eede99647e889b Mon Sep 17 00:00:00 2001 From: "Artem V. Navrotskiy" Date: Mon, 2 Nov 2020 14:38:47 +0300 Subject: [PATCH] Add GC support for `vips.ImageRef` --- vips/image.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/vips/image.go b/vips/image.go index cb3146a6..d7824ed0 100644 --- a/vips/image.go +++ b/vips/image.go @@ -9,6 +9,7 @@ import ( "fmt" "io" "io/ioutil" + "runtime" "sync" "unsafe" ) @@ -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()