Destroying the object

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)

Get Hands-On Computer Vision with Julia now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.