wpfgfx_v0400.dll的内存消耗



我用c#开发的。在我使用WindowsForms一段时间后,我切换到WPF。经过一段时间的开发,我意识到我的应用程序在运行高进程后需要更多的时间来减少内存消耗。对于WinForms,我没有任何问题。所以我用内存分析器分析了它,我发现wpfgfx_v0400.dll保留了很多内存,之后它没有减少。问题是这个库的功能是什么。我知道这是一个原生的WPf库在图形渲染的背景下但是在哪个WPf或对象的特殊控件会被称为这个库呢?

作为快速修复,您可以使用此方法来清除内存泄漏

  public class MemoryManagement
    {
        /// <summary>
        /// Clear un wanted memory
        /// </summary>
        public static void FlushMemory()
        {
            try
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();
                if (Environment.OSVersion.Platform == PlatformID.Win32NT)
                {
                    SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
                }
            }
            catch (Exception e)
            {
            }
        }
        /// <summary>
        /// set process working size
        /// </summary>
        /// <param name="process">Gets process</param>
        /// <param name="minimumWorkingSetSize">Gets minimum working size</param>
        /// <param name="maximumWorkingSetSize">Gets maximum working size</param>
        /// <returns>Returns value</returns>
        [DllImportAttribute("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize", ExactSpelling = true, CharSet =
          CharSet.Ansi, SetLastError = true)]
        private static extern int SetProcessWorkingSetSize(IntPtr process, int minimumWorkingSetSize, int maximumWorkingSetSize);
    }

将该类添加到您的应用程序中,并在遇到内存泄漏时调用FlushMemory方法

最新更新