gocv
gocv copied to clipboard
opencv4.5.3 : Memory leak issue in IMEncodeWithParams
opencv4.5.3 : Memory leak issue in IMEncodeWithParams
Description
\Although I use defer buffer.Close(), IMEncodeWithParams cause memory leak in streaming. If buffer.Close() is executed after declaring a buffer in a for loop to catch the memory leak, the issue that streaming does not work properly occurs.
Steps to Reproduce
Below environment cause memory leak :
var frame *gocv.NativeByteBuffer
defer frame.Close()
for stream_is{
params := []int{gocv.IMWriteJpegQuality, 90}
frame, _ := gocv.IMEncodeWithParams(gocv.JPEGFileExt, img, params)
select {
case c.Frame <- frame:
default:
c.Frame = make(chan []byte, BUFFER_NUM)
fmt.Println("buffer has been flushed...")
}
frame.Close()
}
Below environment cause streaming error :
for stream_is{
params := []int{gocv.IMWriteJpegQuality, 90}
frame, _ := gocv.IMEncodeWithParams(gocv.JPEGFileExt, img, params)
select {
case c.Frame <- frame:
default:
c.Frame = make(chan []byte, BUFFER_NUM)
fmt.Println("buffer has been flushed...")
}
frame.Close()
}
Your Environment
- Operating System and version: ubuntu 18.04
- OpenCV version used: 4.5.3
- How did you install OpenCV?
- GoCV version used: 0.28
- Go version: 1.16.5
- Did you run the
env.sh
orenv.cmd
script before trying togo run
orgo build
? sure
Sorry, I cannot really understand the nature of your error from just the code you present. However seems like something external to GoCV? For sure, Close()
needs to be called on each NativeByteBuffer
returned by each call to gocv.IMEncodeWithParams()
.