Ask Your Question
0

Memory leaks in IplImage

asked 2013-06-19 02:48:01 -0600

Marian gravatar image

updated 2013-06-19 08:08:17 -0600

I have the function, which is leaking memory:

void CAsynchronousGrabDlg::ComputeVariables(FramePtr pFrame)
{
    IplImage *testImage;
    byte *imageData;
    pFrame -> GetImage(imageData);
    VmbUint32_t nWidth, nHeight;
    nWidth = m_pApiController->GetWidth();
    nHeight = m_pApiController->GetHeight();
    testImage = cvCreateImage(cvSize(nWidth, nHeight), IPL_DEPTH_8U, 1);
    cvSetData(testImage, imageData, nWidth);

//  delete imageData;
//  delete testImage;
}

If I try to use delete function, for example delete imageData or delete testImage, I get memory assertion. Can someone tell me, how to correctly deallocate memory for these functions?

edit retag flag offensive close merge delete

Comments

By finding out how Vimba stores its frames and converting it to IplImage or better, Mat. Or you could go the easy way and simply create a copy by iterating over the picture and copying the pixel values.

Notas gravatar imageNotas ( 2013-06-19 05:33:01 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-06-19 08:22:22 -0600

Notas gravatar image

You use delete only on a pointer that you created with new and ONLY then! To release the image, use cvReleaseImage(&testImage). If you had used the Mat-class instad of the old IplImage, you wouldn't have this problem of releasing data. The Mat class has a constructor that accepts a pointer to the data, so you can use that.

edit flag offensive delete link more

Comments

cvReleaseImage(&testImage) also throws memory exception. I don't understand why, but it is true.

Marian gravatar imageMarian ( 2013-06-19 08:40:50 -0600 )edit

Question Tools

Stats

Asked: 2013-06-19 02:48:01 -0600

Seen: 2,061 times

Last updated: Jun 19 '13