Make RAM size free for .NET application [closed]

无人久伴 提交于 2019-12-11 02:33:35

问题


I have created some grid images like booklet pages on a WPF form. When I run my application the system RAM memory size is 1.02 GB (includes all other running applications). When I turn each page RAM size increases by some kb. Finally when I turn more than 150 pages I get an Out Of Memory exception. I understand the exception is caused because there is no space in RAM to open new pages on my application and I tried the following:

     1. BitmapImage image = new BitmapImage();
        image.Dispose();
        image = null;


     2. Gc.Collect();



    3.[DllImport("psapi.dll")]
    public static extern bool EmptyWorkingSet(IntPtr hProcess);

public FreeMem(string programName){

      EmptyWorkingSet(Process.GetCurrentProcess().Handle);
      foreach(Process process in Process.GetProcesses(programName))
      {
            try
            {
                EmptyWorkingSet(process.Handle);
            }
            catch (Exception)
            {
                ...
            }
      } 
}

But I couldn't solve my problem. Can anyone make me clear and solve this?

来源:https://stackoverflow.com/questions/24424466/make-ram-size-free-for-net-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!