c++ - openCV cv::mat release -


when using opencv cv::mat. http://docs.opencv.org/modules/core/doc/basic_structures.html understand sort of smart pointers being used. question is, in order memory optimization.
should call cv::mat release() in order free unused matrices?
or should trust compiler it?

for example think of code:

cv::mat filtercontours = cv::mat::zeros(bwimg.size(),cv_8uc3);   bwimg.release(); (int = 0; < goodcontours.size(); i++) {     cv::rng rng(12345);     cv::scalar color = cv::scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );     cv::drawcontours(filtercontours,goodcontours,i,color,cv_filled);         }  /*% fill holes in objects bwimglabeled = imfill(bwimglabeled,'holes');*/   imagedata = filtercontours; filtercontours.release(); //should call line or not ? 

the cv::release() function releases memory , destructor take care of @ end of scope of mat instance anyways. need not explicitly call in code snippet have posted. example of when needed if size of matrix can vary in different iterations within same loop, i.e.,

using namespace cv; int = 0; mat mymat; while(i++ < relevantcounter ) {     mymat.create(sizeforthisiteration, cv_8uc1);      //do stuff size of mat can vary in different iterations\\      mymat.release(); } 

here, using cv::release() saves compiler overhead of creating pointer in every loop


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -