DirectShow内存泄漏C#

时间:2017-12-04 10:21:10

标签: c# directshow

分配和发布CLSID时出现问题,我使用DirectShow作为USB摄像头,30000个实例后,内存在1000个实例中以1 MB增长。

问题发生是因为de CLSID对象的发布不正确,您能否为该版本提出建议。

int i = 0;
int steps = 30000;
do
{
    Guid filterGraph = new Guid(0xE436EBB3, 0x524F, 0x11CE, 0x9F, 0x53, 0x00, 0x20, 0xAF, 0x0B, 0xA7, 0x70);
    var obj = Activator.CreateInstance(Type.GetTypeFromCLSID(filterGraph));
    Marshal.ReleaseComObject(obj);
    obj = null;

    i++;
    Marshal.CleanupUnusedObjectsInCurrentContext();
    GC.WaitForFullGCComplete(10);
    GC.GetTotalMemory(true);
    GC.Collect();
    GC.WaitForPendingFinalizers();
    GC.Collect();
    string str = string.Format("Test nr {0}/{1}, mem = {2} Mbytes", i, steps,
        Process.GetCurrentProcess().PrivateMemorySize64 / 1024.0 / 1024.0);
    Console.WriteLine(str);

} while (i < steps);

0 个答案:

没有答案