opencvsharp
opencvsharp copied to clipboard
[Question] Will the `Mat` implicit convert to `InputArray` cause memory leak?
Summary of your issue
Such like this, the mat2 implicit convert to MatchTemplate first parameter InputArray:
mat1.MatchTemplate(mat2, xxx);
Environment
Win11 22H2 .NET 7.
The implicit conversion from Mat to InputArray allocates a small amount of memory space that is difficult to free by GC. (I believe this is a design error in the current OpenCvSharp.)
A good way to deal with this problem is to frequently call GC.Collect();.
Alternatively, I recommend the following:
using var src = InputArray.Create(mat1);
using var dst = OutputArray.Create(mat2);
using var xxx_ = InputArray.Create(xxx);
Cv2.MatchTemplate(src, dst, xxx_);
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.