Ask Your Question
0

Should I release cv::Ptr before reassigning?

asked 2018-06-14 14:29:36 -0600

mhaghighat gravatar image

updated 2018-06-14 14:36:37 -0600

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):

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?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2018-06-14 14:46:36 -0600

LBerger gravatar image

updated 2018-06-14 14:52:26 -0600

An doc says :

Template class for smart pointers with shared ownership.

A Ptr<t> pretends to be a pointer to an object of type T. Unlike an ordinary pointer, however, the object will be automatically cleaned up once all Ptr instances pointing to it are destroyed.

Ptr is similar to boost::shared_ptr that is part of the Boost library (http://www.boost.org/doc/libs/release...) and std::shared_ptr from the C++11 standard.

...

and to modify parameters you can use method setVarThreshold

You don't need to release object because opencv will do it

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-06-14 14:29:36 -0600

Seen: 758 times

Last updated: Jun 14 '18