垃圾收集问题 [英] Garbage collection problems

查看:75
本文介绍了垃圾收集问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如很多人所知,我认为垃圾收集对于许多内存分配问题来说是一个很好的解决方案。


然而我知道,没什么是银弹,而不是

甚至GC。


最近一篇关于slashdot的文章
http://developers.slashdot.org/artic.../11/17 / 0552247

证明了这一点。


AC#应用程序泄漏了内存,应用程序将会b / b $ b变慢并且因为内存越来越慢而且

系统在疯狂交换之前一直没有变坏。


为什么?


因为应该销毁的列表没有被销毁。

这类似于Sun在他们的

Java实现中发现的另一个错误。该列表没有被销毁,因为

无论是哪一个都有对该列表的引用,GC可以

不会破坏它。


有趣的是,这个bug很难追溯到

a缺少免费或类似的错误。它需要一个专门的工具

才能找到它(是的,有专门的工具来解决GC内存

分配问题,因为有专门的工具可以解决

非gc内存分配问题)


要吸取的教训是,你必须小心(当使用

GC时)

1)将所有指向未使用内存的指针设置为NULL。

2)如果你想要那些数据,请不要将指针存储在永久结构的GC内存中最终被收集。


上面的错误是该列表在全局

数据结构中注册并且没有被破坏。


如果GC不在那里,那么程序员就可以释放内存中的内存,什么会关闭内存泄漏但是留下了

a悬挂在全球数据结构中的指针!


不是更好的选择。


-

jacob navia

jacob at jacob p oint remcomp point fr

logiciels / informatique
http://www.cs.virginia.edu/~lcc-win32

As many people know, I think that garbage collection is a good
solution for many memory allocation problems.

I am aware however, that nothing is "the silver bullet", not
even the GC.

A recent article in slashdot
http://developers.slashdot.org/artic.../11/17/0552247
proves that.

A C# application was leaking memory, and the application would
become slower and slower because the memory was getting full and the
system was swapping like mad until it just failed.

Why?

Because a list that should be destroyed wasn''t being destroyed.
This is similar to another bug that Sun discovered in their
Java implementation. The list wasn''t being destroyed because
SOMEWHERE there was a reference to that list, and the GC could
not destroy it.

It is interesting to note that this bug is as difficult to trace as
a missing free or similar bugs. It required a specialized tool
to find it (yes, there are specialized tools to solve GC memory
allocation problems as there are specialized tools to solve
non-gc memory allocation problems)

The lesson to be learned is that you have to be careful (when using the
GC) to
1) Set all pointers to unused memory to NULL.
2) Do NOT store pointers to GC memory in permanent structures if you
want that data to eventually be collected.

The above bug was that the list registered itself in a global
data structure and wasn''t getting destroyed.

If the GC wouldn''t have been there, the programmer would have freed
the memory, what would have closed the memory leak but left
a dangling pointer in the global data structure!

Not a better alternative.

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32

推荐答案

jacob navia< ja ** *@nospam.orgwrites:
jacob navia <ja***@nospam.orgwrites:

正如很多人所知,我认为对于许多内存分配问题,垃圾收集是一个很好的解决方案。
As many people know, I think that garbage collection is a good
solution for many memory allocation problems.



< snip错误引用错误引起的错误>

<snip bugs caused by leaving data erroneously referenced>


要吸取的教训是你必须要小心(当使用

GC时)

1)将所有未使用内存的指针设置为NULL。
The lesson to be learned is that you have to be careful (when using the
GC) to
1) Set all pointers to unused memory to NULL.



您声称需要对您关于

GC的建议进行技术讨论,但您没有回答我对此问题的看法。你是否建议(并且已经实施了你的编译器)一套新的好像规则

这样的设置无法优化掉?


-

Ben。

You claimed to want a technical discussion of your suggestions about
GC, but you did not respond to my point about this very issue. Do you
propose (and has your compiler implemented) a new set of "as if" rules
so that such settings can not optimised away?

--
Ben.


Ben Bacarisse写道:
Ben Bacarisse wrote:

jacob navia< ja *** @ nospam.orgwrites:
jacob navia <ja***@nospam.orgwrites:

>正如很多人所知,我认为垃圾收集是解决许多内存分配问题的好方法。
>As many people know, I think that garbage collection is a good
solution for many memory allocation problems.



< snip错误引用错误引起的错误>


<snip bugs caused by leaving data erroneously referenced>


>要吸取的教训是你必须小心(使用
GC)
1)将所有未使用内存的指针设置为NULL。
>The lesson to be learned is that you have to be careful (when using the
GC) to
1) Set all pointers to unused memory to NULL.



您声称想要对您关于

GC的建议进行技术讨论,但您没有回答我对此问题的看法。你是否建议(并且已经实施了你的编译器)一套新的好像规则

这样的设置无法优化掉?


You claimed to want a technical discussion of your suggestions about
GC, but you did not respond to my point about this very issue. Do you
propose (and has your compiler implemented) a new set of "as if" rules
so that such settings can not optimised away?



除非编译器不能优化分配

证明这个内存不能在当前范围内使用。


如果你的编译器这样做,没有任何反应,因为当你

退出该范围GC将会看到内存不再被引用。


可能出现许多并发症。当我被要求时,我的编译器只会进行这样的
优化。在GC设置中,请避免

询问这些优化(删除未使用的作业)。

-

jacob navia

jacob at jacob point remcomp point fr

logiciels / informatique
http://www.cs.virginia.edu/~lcc-win32


jacob navia写道:
jacob navia wrote:

正如很多人所知,我认为对于许多内存分配问题,垃圾收集是一个很好的解决方案。
As many people know, I think that garbage collection is a good
solution for many memory allocation problems.



对,但我更感兴趣的是知道理查德希思菲尔德会是什么?b $ b喜欢C99包括,但C99没有''吨。 :)

Right, but I''m more interested in knowing what Richard Heathfield would
have liked C99 to include, but C99 didn''t. :)


但我知道,没有什么是银弹,而不是即使是GC的b $ b。
I am aware however, that nothing is "the silver bullet", not
even the GC.



IMO,C的主要领域是系统和嵌入式开发。即使通过包括通信,安全开发,b $ b和数据库引擎开发来扩展这个域,GC看起来既不重要,也不太重要。 。


-

Tor< bw **** @ wvtqvm.vw | tr i-za-h a-z>

IMO, the main domain of C is system and embedded development. Even if
extending this domain by including communication, security development
and DB engine development, a GC seems neither important, or of much
interest.

--
Tor <bw****@wvtqvm.vw | tr i-za-h a-z>


这篇关于垃圾收集问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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