问题
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