托管代码中的内存泄漏? [英] Memory leaks in managed code?

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

问题描述



我一直在试图理解文章识别公共语言运行时中的内存泄漏#b $ b在 http://support.microsoft.com/?id=318263


它说垃圾收集器可以

收集并释放内存但从未将其返回给操作系统。

当垃圾收集器无法将仍在使用的对象移动到内存的一部分并释放其余部分时,会发生这种情况。


如何这会发生吗?我知道垃圾收集和内存的基本知识

deallocation,但我不明白GC是如何以及为什么要移动

免费块和对象。是免费空间的唯一目标整合吗?


此外,点#2之间的区别是什么(内存处理但是

从不收集,因为对对象的引用仍然是活动的。)和

点#4(当许多大对象声明为
时,可能导致内存管理不良,并且永远不允许离开范围。)?


最后,有没有什么好的资源可以帮助理解CLR垃圾收集器内部的b $ b工作? (我是.NET初学者!)CLR GC是否使用

固定,还是使用别的东西?


谢谢。


凯文

>怎么会发生这种情况?我知道垃圾收集和内存的基本知识

deallocation,但我不明白GC是如何以及为什么围绕自由块和对象移动。是免费空间的唯一目标整合吗?

您可以在块中分配来自操作系统的内存。整个块必须是免费的,然后才能将它返回给操作系统。因此,通过合并内存来释放阻塞是有道理的。

此外,点#2之间的区别是什么(内存被处理掉了?但是从未收集过,因为对象的引用仍然是活跃的。)和第4点(当许多
大对象被声明并且永远不允许离开时,可能会导致内存管理不良范围。)?

例如,当两个对象相互引用时,第2点就是。

它们永远不会被收集。


点#4完全不同,就像

函数中的一个静态变量引用一个巨大的对象。

最后,有没有什么好处有助于了解CLR垃圾收集器内部工作的资源? (我是.NET初学者!)
CLR GC是否使用固定,还是使用其他东西?



Jeffrey Richter的书有一个很好的解释。请参阅
http://safari.oreilly.com


问候,

Wessel


你指的是Jeffrey Richter的哪本特定书?


谢谢,

Brett


"应用Microsoft .NET Framework编程"

第19章,自动记忆管理(垃圾收集)


问候,

Wessel


星期一,2005年7月18日21:33:57 +0200,brett< ac ***** @ cygen.com>写道:

你指的是Jeffrey Richter的哪本特定书?

谢谢,
Brett





I''ve been trying to understand the article "Identifying Memory Leaks in
the Common Language Runtime" listed on http://support.microsoft.com/?id=318263

It says "The garbage collector can
collect and free the memory but never returns it to the operating system.
This occurs when the garbage collector cannot move the objects that are
still in use to one portion of the memory and free the rest."

How can this happen? I know the basics of garbage collection and memory
deallocation, but I don''t understand how and why the GC would move around
free blocks and objects. Is the only goal consolidation of free space?

Also, what''s the difference betweeen point #2 ("Memory is disposed of but
never collected, because a reference to the object is still active.") and
point #4 ("Poor memory management can result when many large objects are
declared and never permitted to leave scope.")?

And finally, are there any good resources to help understand the inner
workings on the CLR garbage collector? (I''m a .NET beginner!) Does the CLR GC use
"pinning", or does it use something else?

Thanks.

Kevin

解决方案

> How can this happen? I know the basics of garbage collection and memory

deallocation, but I don''t understand how and why the GC would move
around free blocks and objects. Is the only goal consolidation of free
space?
You allocate memory from the OS in blocks. The entire block has to be
free before you can return it to the operating system. So, it makes sense
to free up block by consolidating memory.
Also, what''s the difference betweeen point #2 ("Memory is disposed of
but never collected, because a reference to the object is still
active.") and point #4 ("Poor memory management can result when many
large objects are declared and never permitted to leave scope.")?
Point #2 is for example, when two objects have a reference to eachother.
They will never be collected.

Point #4 is something different entirely, like a static variable in a
function which references a huge object.
And finally, are there any good resources to help understand the inner
workings on the CLR garbage collector? (I''m a .NET beginner!) Does the
CLR GC use "pinning", or does it use something else?


The book from Jeffrey Richter has a nice explanation. See
http://safari.oreilly.com.

Greetings,
Wessel


Which specific book by Jeffrey Richter are you referring to?

Thanks,
Brett


"Applied Microsoft .NET Framework Programming"
chapter 19, "Automatic Memory Management (Garbage Collection)"

Greetings,
Wessel

On Mon, 18 Jul 2005 21:33:57 +0200, brett <ac*****@cygen.com> wrote:

Which specific book by Jeffrey Richter are you referring to?

Thanks,
Brett




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

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