Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Should I release cv::Ptr before reassigning?

Say, I have a

cv::Ptr<cv::backgroundsubtractormog2> mogPtr= cv::createBackgroundSubtractorMOG2(300, 16, true);

Later, I'd like to change the configuration of the background subtractor, but I want to reassign the new object pointer to the same variable (mogPtr):

cv::Ptr<cv::backgroundsubtractormog2> mogPtr= cv::createBackgroundSubtractorMOG2(300, 64, false);

I wonder if I should release the mogPtr before I assign a new pointer to it. Is it a bad idea if I do? Will there be a memory leak if I don't?

Should I release cv::Ptr before reassigning?

Say, I have a

cv::Ptr<cv::backgroundsubtractormog2> mogPtr= mogPtr = cv::createBackgroundSubtractorMOG2(300, 16, true);

Later, I'd like to change the configuration of the background subtractor, but I want to reassign the new object pointer to the same variable (mogPtr):

cv::Ptr<cv::backgroundsubtractormog2> mogPtr= mogPtr = cv::createBackgroundSubtractorMOG2(300, 64, false);

I wonder if I should release the mogPtr before I assign a new pointer to it. Is it a bad idea if I do? Will there be a memory leak if I don't?

Should I release cv::Ptr before reassigning?

Say, I have a

cv::Ptr<cv::backgroundsubtractormog2> mogPtr = cv::createBackgroundSubtractorMOG2(300, 16, true);

Later, I'd like to change the configuration of the background subtractor, but I want to reassign the new object pointer to the same variable (mogPtr):

cv::Ptr<cv::backgroundsubtractormog2> mogPtr = cv::createBackgroundSubtractorMOG2(300, 64, false);

I wonder if I should release the mogPtr before I assign a new pointer to it. Is it a bad idea if I do? Will there be a memory leak if I don't?