Ask Your Question
0

Memory leaks in IplImage

asked Jun 19 '13

Marian gravatar image

updated Jun 19 '13

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?

Preview: (hide)

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 (Jun 19 '13)edit

1 answer

Sort by » oldest newest most voted
0

answered Jun 19 '13

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.

Preview: (hide)

Comments

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

Marian gravatar imageMarian (Jun 19 '13)edit

Question Tools

Stats

Asked: Jun 19 '13

Seen: 2,085 times

Last updated: Jun 19 '13