Assume that the img is a 3 channel Mat in the code. There is a memory leak with the code. I guess that the pointers(reference) in the slice "matsplits" are not deleted with garbage-collection in go. How can I fix it?
for{
matsplits := gocv.Split(img)
matsplits[0].Close()
matsplits[1].Close()
matsplits[2].Close()
}
Kind of above codes cause memory leak. I am sure that the Mat objects in imgarr are closed, but the memory usage is still growing up. Why?
Update: part of codes in my project
processed := 0
for processed < proc.imgNumber {
grayhconcatImg := <-proc.processedImg[0][chindex]
var roiList roilist
var numStartPosList numStartPos
for x := 0; x < 11520-w; x++ {
test := gocv.NewMat()
testRegion := grayhconcatImg.img.Region(image.Rect(x, 0, x+w, h))
gocv.BitwiseXor(chimg, testRegion, &test)
testRegion.Close()
//testsplit := gocv.Split(test)
test.Close()
//testsplit[0].Close()
//testsplit[1].Close()
processed++
}
The memory leak occurs if "testsplit"'s are unmarked. len(testsplit) is 2. I have checked that testsplit[0] and testsplit[1] have been closed correctly after testsplit[i].Close().