处理两个指向的物体

时间:2017-07-12 10:00:50

标签: c# .net ip ip-camera

我有一个应用程序,可以传输ip camera的图像。 问题是,当我关闭应用程序时,它说1个对象仍然存活(未处理)。

出现问题时的代码是:

public override void Render(float dt)
        {
            camera.Lock();
            if (newCameraFrame)
            {
                //Texture tmp = new Texture();
                cameraTexture = camera.Texture;
                newCameraFrame = false;
            }
            base.Render(dt);
            camera.Unlock();
        }

问题出现在行中:cameraTexture = camera.Texture; 我成功地处理了这两个变量,但看起来仍然存在某些变量。 你有任何指示可以告诉我在哪里可以找到问题吗?

1 个答案:

答案 0 :(得分:0)

这些对象是否实现了IDisposable接口?

然后你应该在using块中使用它们:

using(var cameraTexture = camera.Texture())
{
   //..do all necessary things
}

//...here the object will be automatically disposed of

IDisposable()模式是您应该寻找的关键字...

相关问题