EnoxSoftware / OpenCVForUnity

OpenCV for Unity (Untiy Asset Plugin)
https://assetstore.unity.com/packages/tools/integration/opencv-for-unity-21088
557 stars 175 forks source link

[2.6.0] knnMatch has memory leak #189

Closed Rombond closed 3 months ago

Rombond commented 3 months ago

After using knnMatch in the Update loop i've got a lot of memory leak. (Editor and Build)

Here is the code:

FlannBasedMatcher flann = FlannBasedMatcher.create();
string flannConf = Utils.getFilePath("conf.yml");
flann.read(flannConf);
//.... ORB detectAndCompute
List<MatOfDMatch> matches = new List<MatOfDMatch>();
try
{
    flann.knnMatch(des1, des2, matches, 2);
}
catch (CvException ex)
{
    kp2.Dispose();
    des2.Dispose();
    for (int i = 0; i < matches.Count; i++)
    {
        matches[i].Dispose();
    }
    matches.Clear();
    matches = null;
    continue;
}
kp2.Dispose();
des2.Dispose();
for (int i = 0; i < matches.Count; i++)
{
    matches[i].Dispose();
}
matches.Clear();
matches = null;

I tried to put as much as possible of Dispose() but it doesn't affect the memory leak, did i miss something ? In profiler and memory profiler, memory leak is in "Untracked" type.

EnoxSoftware commented 3 months ago

Thank you very much for reporting. Could you send me a simple project that can reproduce this problem? https://enoxsoftware.com/opencvforunity/contact/technical-inquiry/

Rombond commented 3 months ago

I have sended it 13 june, any news on it ? It is really critical to me

EnoxSoftware commented 3 months ago

@Rombond For some reason your email does not seem to have reached my mail server. I am sorry, but could you please resend me a simple code or project that reproduces the occurrence of the memory leak to the following e-mail address? store@enoxsoftware.com

EnoxSoftware commented 3 months ago

@Rombond Upon investigation, a bug was found in the C# and C++ data passing process code. OpenCVForUnity 2.6.1 has already been fixed and updated. Thank you for your report.