memory management of Mat
I read in the below link about the Mat variables about how it allocates and deallocates memory http://docs.opencv.org/doc/tutorials/...
In the link, its mentioned that Mat is that you no longer need to manually allocate its memory and release it as soon as you do not need it
What I don't understand it how and exactly when it will de-allocate the memory of a Mat.
Suppose I am running my Opencv Application.
Whether it will de-allocate its memory when I exit the running Application(when I press Ctrl+C)
Please clarify me on this.
Thanks in advance Sarjoondeen.
basically when the Mat is not needed anymore (runs out of scope for example). Ctrl+C'ing is a special case, and not so much related to this because in that case the OS is releasing all memory in use by the killed process.
cv::Mat holds an internal refcount, which gets increased, once you assign/copy it, like
Mat a=b;
and gets decreased, when an instance goes out of scope(like: leaving a pair of {} braces)if the refcount goes down to zero, it will destroy itself, very similar to a std::shared_ptr
so, to use it properly, avoid any C constructs, like raw pointers to that (you'll inevitably thrash the refcount)
again this is c++, not C.
Thanks For you reply.. I get it now..