IntPtr causing memory leak?

This function is in a loop. When I run the program, the line with IntPtr is giving me memory problems, I've put delete[], but it still doesn't solve the memory problem, can anyone help please? thanks

1
2
3
4
5
6
7
8
9
10
11
void showImage(IplImage *img,System::Windows::Forms::PictureBox^ picturebox)
{

IntPtr ip(new unsigned char[img->widthStep*img->height]); // this line causing memory usage to keep going up very fast

//memcpy(ip.ToPointer(),img->imageData,img->widthStep*img->height);

//picturebox->Image = gcnew Bitmap(img->width,img->height, img->widthStep, System:rawing::Imaging::PixelFormat::Format24bppRgb, ip);

delete[] ip;
} 
You didn't allocate ip with new, so you shouldn't be deleting it.

You're passing something new'd to ip's constructor (which is different).

Definitely get rid of that delete[] ip line.

As for any memory leak / problem with IntPtr, it's impossible for us to tell without seeing IntPtr.
Topic archived. No new replies allowed.