Skip to content

Commit ae9c84e

Browse files
Update example_mozjepg_image.go to close image (#271)
close image after it is open in the example. Otherwise it could cause memory leak. This actually happened in my small server. A function was called multiple times to resize images, and all the images were very large. The server got frozen due to memory explosive.
1 parent 132f343 commit ae9c84e

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

examples/jpeg/example_mozjpeg_image.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func ExampleMozJPEGEncode() {
2828

2929
inputImage, err := vips.NewImageFromFile("resources/jpg-24bit-icc-adobe-rgb.jpg")
3030
checkError(err)
31+
defer inputImage.Close()
3132
checkError(inputImage.OptimizeICCProfile())
3233

3334
ep := vips.NewJpegExportParams()

0 commit comments

Comments
 (0)