Opencv deallocates the memory automatically as well as automatically allocates the memory for output function parameters most of the time. Opencv has been around since 2001. In this post i would like to discuss what happens when cv mat is passed around.