Ask Your Question

Revision history [back]

I am having trouble deleting a video capture object in C++.

I define the video capture as a pointer VideoCapture* capture; I then initialize the pointer to null in the constructor capture=NULL; When ready to use it i initialize it capture=new VideoCapture; I can then use it and read a camera just fine. When I am ready to close out the program I release it If(capture->IsOpened) capture->release; This works.
However when I go to delete the capture object, I doesn't work, and I get an error if(capture) delete capture; If I don't try to delete it, I get a memory leak If I try to delete it without releasing it, I get errors If I don't try to release it or delete it, I get errors. Does anybody have an idea of how to release it and delete it without getting a bunch of errors?