OpenCVForUnity icon indicating copy to clipboard operation
OpenCVForUnity copied to clipboard

[2.6.6] calib3d_Calib3d_findChessboardCornersSB_10 Method cause HUGE memory leak

Open soimy opened this issue 8 months ago • 3 comments

Tested in ArUcoCameraCalibrationExample project When use Chessboard Type and enable useFindChessboardCornersSBMethod(which is true by default), huge memory leak in profiler(around 1G per frame).

After tracking down the csharp code. The API causing this is calib3d_Calib3d_findChessboardCornersSB_10 from dllImport.

soimy avatar May 28 '25 04:05 soimy

Thank you for your reporting.

Could you tell me the environment you tested? Unity version : OpenCVforUntiy version : Editor Platform :

Which Category is significantly increased in the profiler? https://docs.unity3d.com/2021.3/Documentation/Manual/ProfilerMemory.html

EnoxSoftware avatar May 28 '25 14:05 EnoxSoftware

Unity version: LTS 2022.3.29f1 OpenCVforUnity: 2.6.6 Editor Platform: MacOS Sequoia 15.5 on M4 mini

Image

But when I use memory profiler, untrack memory amount is way smaller, but still at a rapid growth over time.

Image

soimy avatar May 29 '25 04:05 soimy

Thank you very much for your detailed report.

We were able to reproduce the issue on our environment (Silicon Mac / arm64) as well. When useFindChessboardCornersSBMethod is enabled and the calib3d_Calib3d_findChessboardCornersSB_10 function is used, the Unity profiler shows a significant increase in Native memory usage — approximately 1GB per frame.

However, when running the same code on an Intel Mac (x86_64), we did not observe a continuous increase in Allocated Memory Distribution under Native memory. The behavior appears stable on that architecture.

Additionally, we analyzed the memory usage using Xcode’s Instruments tool, and as shown in the attached screenshot, no significant memory leaks were detected.

Image

It’s currently unclear whether this discrepancy is due to a Unity profiler bug specific to the arm64 architecture or caused by some other factor, but we will continue investigating the issue.

EnoxSoftware avatar May 30 '25 14:05 EnoxSoftware