This code works fine to the last line. It saves the correct image on disk, but when the function exits, a "memory leak" occurs - damage to the heap. I read that Mat should not be explicitly released. In my case, it is reset both with release and without release. Please, help.
void CannyEdgeDetectionFilter::applyFilter(Mat& mat, Mat& mixedBandsMat)
{
vector<Mat> bandWiseImages;
split(mat, bandWiseImages);
int numChannels = mat.channels();
int type = mat.type();
int singleChannelDepth = 8*mat.elemSize1();
for (int i = 0; i < numChannels; i++)
{
Canny(bandWiseImages[i], bandWiseImages[i], m_LowerThreshold,
m_UpperThreshold, m_Kernel.rows);
}
mixedBandsMat.create(mat.rows, mat.cols, mat.type());
merge(bandWiseImages, mixedBandsMat);
#if 1
int bandWiseVecSize = bandWiseImages.size();
for(int i = 0; i < bandWiseVecSize; i++)
bandWiseImages[i].release();
bandWiseImages.clear();
#endif
imwrite("D:\\testAfterCannyEdgeDetetionFilter.jpg", mixedBandsMat);
mixedBandsMat.release();
}
source
share