AppDomain,WebBrowser内存泄漏 [英] AppDomain, WebBrowser Memory Leak

查看:84
本文介绍了AppDomain,WebBrowser内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我对WebBrowser控件中存在的内存泄漏以及以下线程(http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/8a2efea4-5e75)进行了大量研究-4e3d-856f-b09a4e215ede)告诉我,唯一真正的方法是回收 WebBrowser占用的内存是将控件加载到单独的appdomain中.

I have done a lot of research on the memory leaks present in the WebBrowser control, and the following thread (http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/8a2efea4-5e75-4e3d-856f-b09a4e215ede) told me that the only real way to reclaim the memory eaten up by WebBrowser is to load the control in a separate appdomain.

我继续这样做,但是当我卸载创建WebbBrowser的AppDomain时(使用AppDomain.Unload()),内存仍然没有释放.我正在任务管理器中查看进程的专用字节(准确无误,我感兴趣的是什么) 在)中以确认这一点.内存使用量保持在50MB +,而不是默认的5MB.

I went ahead and did this, but when I unload the AppDomain that the WebbBrowser is created in (using AppDomain.Unload()), the memory is still not freed. I am looking at the Private Bytes of the process in Task Manager (which is accurate and what I'm interested in) to confirm this. The memory usage stays at 50MB+ instead of its default 5MB.

这是我的代码:

Form1.vb

Imports System.Reflection

Public Class Form1
 Private ad_WBInst As AppDomain
 Private m_WBInst As WBInst


 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

 End Sub

 Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

  Dim adSetup As New AppDomainSetup

  adSetup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory

  ad_wbInst = AppDomain.CreateDomain("WBInst", AppDomain.CurrentDomain.Evidence, adSetup)

  'start the class in a new appdomain
  m_wbInst = DirectCast(ad_wbInst.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, (GetType(WBInst)).FullName), WBInst)

 End Sub

 Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

  AppDomain.Unload(ad_wbInst)

 End Sub
End Class

推荐答案

在Internet周围,关于网络和内存泄漏的问题无穷无尽,现在您再添加一个.

Around Internet there are endless questions about Net and memory leaks and now you add again one.

其原因是最终用户工具任务管理器",它提供了内存消耗的指示,但并不十分精确.

The reason of that is the end user tool Task Manager, which gives an indication of the memory consumption but is far from precise. 

由于指令的寻址再次回到零,导致内存泄漏导致计算机关闭.

A memory leak has as result a computer shut down, because the addressing of the instructions goes back to zero again.

任务管理器是最终用户工具.

The task manager is an end user tool.

您不是唯一受此约束的人,​​所以我们得到了所有这些消息.

You are not the only one bound to that, and so we get all those messages.

如果这确实是一个问题(不仅是taskmanager的介绍),那么还可以在Internet上搜索免费的内存分析器.

If it is really a problem (not only the presentation of taskmanager) than search on Internet for a freeware memory profiler. 

那样Google将成为您的朋友.

Google will be your friend by that.

这里有一个活跃的程序员,他曾经创建过一些东西来降低任务管理器的性能,虽然减慢了他的程序的执行速度,但是他的客户很满意.

There is an programmer here active who once has created something to bring the measurement in task-manager down, it slowed down his program but his client was happy.

 


这篇关于AppDomain,WebBrowser内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆