From: "Jörg W Mittag" Date: 2010-08-21T08:15:15+09:00 Subject: Re: Ruby GC question (MRI, JRuby, etc) Chuck Remes wrote: > On Aug 18, 2010, at 8:58 AM, Robert Klemme wrote: >> 2010/8/17 Chuck Remes : >>> My basic understanding of the garbage collectors in use by the various Ruby runtimes is >>> that they all search for objects from a "root" memory object. If an object cannot be reached >>> from this root, then it is collected. >> There is a small error in the wording above. While the issue has been >> explained already I want to stress this point because this is a >> mistake many new to GC make and it explains some weird effects that >> special tests show. It should have read >> >> If an object cannot be reached from this root, then it _can be_ collected. >> >> Small change, big difference. :-) > Ha! Yes, quite true. Depending upon the GC algo in use, some objects > may never be collected even though they are eligible for > collection. In particular, the GC algorithms in MRI and YARV are specifically designed with the assumption that they will never actually run in 99.999% of all cases. They are designed for scripting, where a script doesn't even allocate enough memory to trigger a collection, runs for a couple of seconds and then exits, after which the OS simply reclaims the memory: no GC needed. That's why YARV and especially MRI are so exceptionally bad for server loads. It's also why REE can never be merged into mainline. Unless *specifically* guaranteed by the language specification, you simply cannot make any assumptions about when or even if objects get collected. Not even Python makes such guarantees, popular myths notwithstanding. jwm