内存泄漏C# [英] Memory Leaks C#

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

问题描述

我想了解内存的概念泄漏更好的任何人都可以点一些有用的信息,这将有助于我更好地理解到底是什么内存泄漏是,我如何才能找到他们在我的代码。

I am trying to understand the concept of memory leaks better can anyone point up some useful information that will help me better understand exactly what memory leaks are and how I would find them in my code.

感谢您

推荐答案

有多种内存泄漏,但在一般的期限是指一些一种资源已不再使用,但仍占用的内存。如果你有很多的你的应用需要大量的内存,并最终你用完了它。

There are many kinds of memory leaks, but in general the term refer to some kind of resource that is no longer used, but still takes up memory. If you have many of those your application takes a lot of memory and eventually you run out of it.

在C#中,这些都是一些常见的内存泄漏:

In C#, these are some common memory leaks:


  • 不删除事件听众。与该引用外部对象将保留这些对象活着匿名方法或lambda表达式创建的任何事件侦听器。请记住删除事件侦听器时,他们不再被使用。

  • 保持数据库连接或结果集打开时不使用它们。记得拨打的Dispose()上的所有的IDisposable 的对象。 使用使用语句

  • 呼吁采用对C函数/调用的内存分配,你永远不会再放开。

  • Not removing event listeners. Any event listener that is created with an anonymous method or lambda expression that references an outside object will keep those objects alive. Remember to remove event listeners when they are no longer used.
  • Keeping database connections or result sets open when they are not used. Remember to call Dispose() on all IDisposable objects. Use the using statement.
  • Call to C functions using p/Invoke which allocate memory which you then never release.

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

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