Wanderinglazyeye
asked on
properly delete pointer - hopefully a quickie
The loop below is toggled by a "preview" button. It show the images just fine, but it runs my memory up fast because if I put the line "cvReleaseImage(&pimage_co py) anywhere to release the memory, I get a passing null pointer even though I think I am destroying pointers as I create them. How do I reconcile? Should I use smart pointers?
while (CameraStatusInst.Start_Button_Status(false, false))
{
IplImage* pimage_copy = contour_image;
if (pimage_copy != NULL)
{
int key=0;
cvNamedWindow("Mouse Vision", 1);
cvShowImage("Mouse Vision", pimage_copy);
key = cvWaitKey(20);
//cvReleaseImage(&pimage_copy) <-------------works when commented out
}
else
{
cvReleaseImage(&pimage_copy);
}
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>>> cvReleaseImage(&pimage_cop y)
you pass the 'address' of pimage_copy to cvReleaseImage. So cvReleaseImage takes a IplImage** ?? That is strange beside cvReleaseImage would expect an array of IplImage pointers rather than a single pointer.
>>>> while (CameraStatusInst.Start_Bu tton_Statu s(false, false))
>>>> {
>>>> IplImage* pimage_copy = contour_image;
I can't see how that in that while loop you ever would get a pimage_copy == NULL. Even then, why do you call cvReleaseImage(&pimage_cop y); with the address of a NULL pointer. What do you expect from that?
I would guess the above loop would fail in the second iteration cause I can't see how contour_image could get a different value (or NULL) in the meantime.
Regards, Alex
you pass the 'address' of pimage_copy to cvReleaseImage. So cvReleaseImage takes a IplImage** ?? That is strange beside cvReleaseImage would expect an array of IplImage pointers rather than a single pointer.
>>>> while (CameraStatusInst.Start_Bu
>>>> {
>>>> IplImage* pimage_copy = contour_image;
I can't see how that in that while loop you ever would get a pimage_copy == NULL. Even then, why do you call cvReleaseImage(&pimage_cop
I would guess the above loop would fail in the second iteration cause I can't see how contour_image could get a different value (or NULL) in the meantime.
Regards, Alex
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Its filling the correct values - the preview window opens up, and the expected images are seen. I removed the loop (pimage_copy == NULL), it works fine. yeah my brain farted.
IplImage* pimage_copy = cvCloneImage(contour_image );
Tried this and releasing it, get run time errors.
Problem is a memory leak when I open the preview window and stops when I close it. It jumps by 10k/second (about) until program crashes. I preview the images by using the sharing image solution shown in another EE topic that was solved earlier. My preview code is a thread launched from a GUI event.
Would it be helpful to anyone to post the entire thread?
IplImage* pimage_copy = cvCloneImage(contour_image
Tried this and releasing it, get run time errors.
Problem is a memory leak when I open the preview window and stops when I close it. It jumps by 10k/second (about) until program crashes. I preview the images by using the sharing image solution shown in another EE topic that was solved earlier. My preview code is a thread launched from a GUI event.
Would it be helpful to anyone to post the entire thread?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I dropped the loop. In fact, I dropped the threads. I took your idea about the evaluating whether threads were necessary, and simply made two program versions. One with threads, one without. What I found was that the version without thread BLAZED. Still, it provided a learning experience.
Thanks ItsMe
WLE
Thanks ItsMe
WLE
Open in new window