|
-
April 9th, 2011, 01:56 PM
#1
IntPtr causing memory leak?
this function is in a loop, and when i run the program, the line with intptr is giving me memory problems, can anyone help please? thanks
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;
}
-
April 9th, 2011, 02:24 PM
#2
Re: IntPtr causing memory leak?
Your code is not a VC++ nor a native C++.
Try to ask in the Managed C++/CLI forum
Victor Nijegorodov
-
April 9th, 2011, 06:47 PM
#3
Re: IntPtr causing memory leak?
Victor is right that you're in the wrong section but maybe we can get this one sorted out quickly.
Keep in mind that, though the name suggests something else, IntPtr is no pointer! It's just an integral type with the machine's word size, IOW pointer size. (Maybe the should've better named it PtrInt.) Therefore, this doesn't make sense and your memory leak is no surprise:
 Originally Posted by Qmage
I wonder why this didn't raise a compilation error in the first place. There is a conversion from IntPtr to void *, but according to MSDN it's explicit. Try this instead:
Code:
delete[] ip.ToPointer();
I didn't check the commented-out portions of your code.
In case this doesn't solve the problem and/or you have more questions about C++/CLI, please post them in the appropriate section.
Please use code tags when posting code.
Ah, and... Welcome to CodeGuru!
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|