在C#.NET 2.0应用程序的ActiveX Flash组件会导致内存泄漏?应用程序、组件、内存、NET

由网友(懒得讨好)分享简介:我们有一个C#/。NET 2.0 WinForm的,上面有一个ActiveX控件ShockwaveFlashObject。该程序遍历内容的安排和控制,全屏遍地显示出来,像这样:We have a C#/.NET 2.0 WinForm with an ActiveX ShockwaveFlashObject cont...

我们有一个C#/。NET 2.0 WinForm的,上面有一个ActiveX控件ShockwaveFlashObject。该程序遍历内容的安排和控制,全屏遍地显示出来,像这样:

We have a C#/.NET 2.0 WinForm with an ActiveX ShockwaveFlashObject control on it. The program loops through a schedule of content and displays it over and over on the control, fullscreen, like this:

axFlash.BringToFront();
axFlash.Movie = scheduleItem.FilePath;
axFlash.Show();
axFlash.Play();

这个伟大的工程,但经过几个跑两天,形式上的Flash ActiveX控件驻留将抛出这样一个异常:

This works great, but after a couple of days running, the form on which the Flash ActiveX control resides will throw an exception like this:

System.Runtime.InteropServices.SEHException: External component has thrown an exception.
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.DefWndProc(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.AxHost.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

综观任务管理器,我看到我们的节目已经分配几乎所有的可用内存的机器上。 (〜500MB)

Looking at the taskmanager, I see that our program has allocated virtually all of the available memory on the machine. (~500MB)

是由垃圾收集非托管的ActiveX(COM)组件? 是否有Flash9.ocx或Flash10.ocx?一些已知的内存泄漏 在任何想法我怎么能得到一个外部组件(闪光灯的ActiveX在这种情况下),以释放资源回无需重新启动程序?可以定期用一个新的解决的事情?重新创建ShockwaveFlashObject 也许重启程序定期仅仅是不错的选择的? Are ActiveX (COM) components unmanaged by Garbage Collection? Is there some known memory leak in Flash9.ocx or Flash10.ocx? Any ideas how I can get an external component (Flash ActiveX in this case) to release resources back without restarting the program? Could periodically re-creating the ShockwaveFlashObject with a "new" fix things? Maybe restarting the program periodically is the only good option?

推荐答案

通常都写在非托管code,因此ActiveX组件将不会被清理由CLR垃圾收集器。你需要确保你释放任何引用到ActiveX控件。我认为这只会造成一个问题,但如果你现在重新创建ActiveX控件的很多。

ActiveX components typically are written in unmanaged code, and therefore would not be cleaned up by the CLR garbage collector. You need to ensure you release any references to the ActiveX control. I think this would only create an issue though if you are recreating the ActiveX control a lot.

您可以使用性能监视器来测量由CLR内存使用情况和内存使用情况的整体。您可以使用此来缩小是谁泄漏的内存。 (差别是由于非托管code,如ActiveX控件)

You can use perfmon to measure memory usage by the CLR and memory usage overall. You can use this to narrow down who is leaking the memory. (the difference would be due to unmanaged code, like the activex control)

如果你这样做孤立​​的ActiveX或闪光灯控制,试图删空与不消耗内存假的对象,这些对象。这应该让你确定它是泄漏源。

If you do isolate it to the ActiveX or flash control, trying stubbing out those objects with a fake object that doesn't consume memory. This should let you verify it is the source of the leak.

阅读全文

相关推荐

最新文章