In order to avoid problems with memory allocation when using C++, it is recommended that you release C++ objects when you are done working with them.
Consider the following example:
filename = joinpath(pwd(), "sample-images", "cat-3352842_640.jpg");
img = imread(filename);
TheĀ img object contains a reference to a C++ object. Setting img to nothing does not guarantee that C++ resources will be released until you close Julia.
In order to release the resource, you need to call the destroy function, which is part of theĀ Open CV package:
destroy(img)