Plugging a value to a released image?
I saw 开发者_如何转开发in code using openCV the following:
cvReleaseImage(&img);
img= 0;
Why and how do they put 0 in the image after they released it?
Thanks a lot
Some people believe that zeroing a pointer after deletion, will help them catch bugs.
The OpenCV authors evidently thought so, hence, cvReleaseImage
does that.
And then the author of the code you’ve shown also believed that, and probably was not aware that cvReleaseImage
already does that zeroing.
So, the extra zeroing is 100% redundant, just unnecessary code.
The zeroing done by cvReleaseImage
is believed by some to help with catching bugs, while others believe the opposite, that it instead mainly hides bugs.
Cheers & hth.,
It is not the image itself, it is a pointer to the image that they set to 0 (NULL) after the image has been released.
It ensures that the image pointer will not point to something else. Later, you also can check whether the pointer is point to NULL (which is 0).
Hope it helps.
精彩评论