0

I am wondering if OpenCV Mat default constructor already allocates the memory? as indicated in doc

>     These are various constructors that form a matrix. As noted in the Automatic Allocation of the Output Data, often the default constructor
> is enough, and the proper matrix will be allocated by an OpenCV
> function.

Does this mean that the deallocation happening at the end of my program is proper. Is that correct?

Actually, I am having a (core dump) error at the memory deallocation phase at program's end. My initial code introduces an OpenCV Mat i.e. Mat A without initialize it which creates the error. I fixed this error by using initialization i.e. A = Mat::zeros(...)

I want to confirm my previous doubt. If it is true, it is quite inconvenient to have to initialize Mat every time it is declared

Sorry for my bad explanation! please respond to me if I am not clear enough

2
  • I forget to mention that the Mat variable is declared in a class and the class destructor creates the memory error Commented Mar 28, 2016 at 8:01
  • Show us a minimal case please Commented Mar 28, 2016 at 8:28

1 Answer 1

2

Does this mean that the deallocation happening at the end of my program is proper. Is that correct?

cv::Mat allocates memory by itself and release it when all cv::Mat that shares the same data go out of scope (something similar to std::shared_ptr).

I want to confirm my previous doubt. If it is true, it is quite inconvenient to have to initialize Mat every time it is declared

No it is wrong. However, since you did not show a code I can just make a guess that you are not linking OpenCV yo your project correctly because it is famous case that a non well linked OpenCV causes errors at cv::Mat destruction stage.

Sign up to request clarification or add additional context in comments.

5 Comments

sorry I tried but cannot replicate the error in a small project! btw, could you please explain a bit further about the linking error of OpenCV? but my program does not have that error all the time but only in one case
I do not have much information. However, When you mix 32-64 or release-debug binaries while linking to OpenCV this problem may occur. So, double check all the dlls and libs
the problem is fixed (in cmd line run) if I use initialization i.e. A = Mat::zeros(...). However, if I trace code using debug, it still appears
No it did not fixed. it has been hidden. if you are sure that you are not doing any thing wrong, sjut make sure that OpenCV is linked perfectly with all needed configuration and should be solved. Or put the code you are using so we can make sure that nothing is incorrect in it
I'll try again to compile a smaller code and upload

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.