Assembly动态加载内存泄露的问题

string strDllFile = Application.StartupPath + "\\ClassLibrary1.dll";
            System.Reflection.Assembly theDll = System.Reflection.Assembly.LoadFrom(strDllFile);
            Form newForm = (Form)theDll.CreateInstance("ClassLibrary1.Form1");
            newForm.Show();

这是一段动态加载Dll,并且载入窗体,显示的代码。

 

private void button1_Click(object sender, EventArgs e)
        {
            string strDllFile = Application.StartupPath + "\\ClassLibrary1.dll";
            System.Reflection.Assembly theDll = System.Reflection.Assembly.LoadFrom(strDllFile);
            Form newForm = (Form)theDll.CreateInstance("ClassLibrary1.Form1");
            newForm.Show();
        }

第一次是5M

第二次是7M

第三次是8M

每Click一次,内存增加1m,为什么呢?

 System.Reflection.Assembly.LoadFrom();

每次LoadFrom都会重新Load DLL进来,所以每次都会增加内存。

 

我只是一个你们认为技术有问题的人。

 

源文件在此https://files.cnblogs.com/youxi/WindowsFormsApplication1.rar

posted @ 2010-05-22 21:41  人生就是幽默  阅读(550)  评论(2编辑  收藏  举报