fix: 修复 RunMulti 中 Mat 所有权语义不明确导致的潜在 Dispose 问题 (#2730)

This commit is contained in:
Ayu0K
2026-02-05 01:37:18 +08:00
committed by GitHub
parent 2ced2862b3
commit a24dd1c778

View File

@@ -95,7 +95,10 @@ public class Rec(
// .AsParallel()
.Select(src =>
{
using var channel3 = src.Channels() switch
Mat? channel3 = default;
try
{
channel3 = src.Channels() switch
{
4 => src.CvtColor(ColorConversionCodes.BGRA2BGR),
1 => src.CvtColor(ColorConversionCodes.GRAY2BGR),
@@ -110,6 +113,15 @@ public class Rec(
}
return result;
}
finally
{
// Only dispose Mats created in this scope
if (channel3 != null && !ReferenceEquals(channel3, src))
{
channel3.Dispose();
}
}
})
.Select(inputTensor =>
{