防止 WPF 中的内存泄漏 [英] Prevent memory leaks in WPF

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

问题描述

使用 WinForms 后,您必须在使用 gdi 对象、事件处理程序、来自本机代码的对象等之后释放内存.

Working with WinForms you have to free memory after using gdi objects, event handlers, objects from native code, etc.

WinForms 中,我曾经在 dispose 方法中删除例如事件处理程序.

In WinForms I used to remove for example event handlers in the dispose method.

Wpf 中防止内存泄漏的最佳解决方法是什么?和在 Winforms 中使用 Dispose pattern 一样吗?到底,我是否需要关心 Wpf 中的事件处理程序、gdi 对象?运行时创建的资源(Brushes 等)怎么样?

What is the best workaround to prevent memory leaks in Wpf? Is it the same as in Winforms using Dispose pattern? At all, do I have to care about event handlers, gdi objects in Wpf? What about the runtime created resources(Brushes, etc)?

推荐答案

This 博文列出了导致 WPF 应用程序内存泄漏的最常见情况.

This blog post lists the most common situations that cause memory leaks in WPF applications.

  • 父窗口中对象的事件处理程序
  • 从静态对象注册事件
  • 使用计时器
  • 数据绑定
  • 更改文本框的 Text 属性

它还描述了如何解决这些常见问题.

It also describes how to fix these common issues.

另一种好方法是在遵循标准指南的同时开发应用,然后使用某种分析器来确定任何内存泄漏或性能瓶颈.

Another good approach is to develop an app while following the standard guidelines and then use some kind of profiler to determine any memory leaks or performance bottlenecks.

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

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