Bug #216 [ruby-core:17518]
Memory leaks in 1.8.6p230 and p238
| Status : | Closed | Start : | 07/03/2008 | |
| Priority : | Urgent | Due date : | ||
| Assigned to : | - | % Done : | 0% |
|
| Category : | - | |||
| Target version : | - | |||
Description
WARNING: Do not use Ruby 1.8.6 releases p230 through p238 in production! There are bugs in the Ruby interpreter that cause it leak memory. Please use a Ruby release that's based on a patched version of the p111 or p114 code until this is resolved. I've put together code which demonstrates this at: http://pastie.org/226715 -igal
History
07/03/2008 11:51 PM - Igal Koshevoy
Rolando Abarca: No, my test merely proves that a memory leak exists, but doesn't identify where. If you or someone else has time to try to build a more specific test, it'd be much appreciated because it'll be much easier for the developers to identify the actual cause of the memory leak and address it.
07/04/2008 06:07 AM - Anonymous
For what it's worth: I seem to be experiencing the memory leak in p256 as well: ruby 1.8.6 (2008-06-30 patchlevel 256) [i686-linux] I don't know much about it yet, but I'm seeing the leak in two completely different long-running processes, neither of which is based on anything Rails-related. (One is a server running nitro/og/webrick, the other is a home-grown game admin system.) Regards, Bill
07/04/2008 06:31 AM - Anonymous
I can also confirm memory leaks running a bunch of different ruby code including rails, merb and various daemons. -Ezra
07/05/2008 05:46 AM - Rolando Abarca
Here are some other tests, and here are my results. VmSize is displayed before and after running the main loop (check the test files). Test files are here: http://pastie.org/227949 test04.rb is the only one not leaking. rolando@dev02:~/sandbox/ruby_memory_test$ ruby run_tests.rb test01.rb ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-linux] VmSize: 3108 kB VmSize: 3240 kB ruby 1.8.6 (2008-07-03 patchlevel 265) [i686-linux] VmSize: 3116 kB VmSize: 96968 kB ==== test02.rb ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-linux] VmSize: 2972 kB VmSize: 3104 kB ruby 1.8.6 (2008-07-03 patchlevel 265) [i686-linux] VmSize: 2984 kB VmSize: 115580 kB ==== test03.rb ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-linux] VmSize: 2972 kB VmSize: 3104 kB ruby 1.8.6 (2008-07-03 patchlevel 265) [i686-linux] VmSize: 2984 kB VmSize: 115580 kB ==== test04.rb ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-linux] VmSize: 2976 kB VmSize: 2976 kB ruby 1.8.6 (2008-07-03 patchlevel 265) [i686-linux] VmSize: 2984 kB VmSize: 2984 kB regards, rolando./
07/05/2008 08:56 AM - Igal Koshevoy
Rolando Abarca, Excellent work, your sample code clearly demonstrates the memory leak and narrows its location. I can confirm that p238 and p265 leak memory on the first three tests, while p111ubuntu is fine. I've played with this further and provided a broader series of Regexp related methods that are affected: http://pastie.org/228006 -igal
07/05/2008 03:50 PM - Yukihiro Matsumoto
Hi, In message "Re: [ruby-core:17608] [Ruby 1.8 - Bug#216] Memory leaks in 1.8.6p230 and p238" on Sat, 5 Jul 2008 08:53:17 +0900, Igal Koshevoy <redmine@ruby-lang.org> writes: |Excellent work, your sample code clearly demonstrates the memory leak and narrows its location. I can confirm that p238 and p265 leak memory on the first three tests, while p111ubuntu is fine. The following patch from ruby_1_8 should fix the leak. Could you try? matz. Index: re.c =================================================================== --- re.c (revision 16437) +++ re.c (revision 16438) @@ -927,6 +927,7 @@ } if (result < 0) { + re_free_registers(®s); rb_backref_set(Qnil); return result; } @@ -943,6 +944,7 @@ } re_copy_registers(RMATCH(match)->regs, ®s); + re_free_registers(®s); RMATCH(match)->str = rb_str_new4(str); rb_backref_set(match);
07/06/2008 02:22 AM - Igal Koshevoy
Good news, I think the memory leak problem is fixed. I've applied Matz's re.c patch to my copy of p265 (head of ruby_1_8_6) and ran it against (1) my earlier test which used a complete Rails stack, (2) Rolando Abarca's contributed tests, and (3) my later tests for String/Regexp. Memory usage for all these is now stable. Matz, thank you so much for resolving this. And thank you Rolando for contributing the specific test case that helped isolate the leak. -igal
07/06/2008 04:19 AM - Rolando Abarca
Hi, On Jul 5, 2008, at 2:46 AM, Yukihiro Matsumoto wrote: > The following patch from ruby_1_8 should fix the leak. Could you try? > > matz. yes, it works fine :-) Here are the results from my tests: test01.rb ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-linux] VmSize: 3108 kB VmSize: 3240 kB ruby 1.8.6 (2008-07-03 patchlevel 265) [i686-linux] VmSize: 3116 kB VmSize: 3248 kB ==== test02.rb ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-linux] VmSize: 2972 kB VmSize: 3104 kB ruby 1.8.6 (2008-07-03 patchlevel 265) [i686-linux] VmSize: 2988 kB VmSize: 3120 kB ==== test03.rb ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-linux] VmSize: 2972 kB VmSize: 3104 kB ruby 1.8.6 (2008-07-03 patchlevel 265) [i686-linux] VmSize: 2984 kB VmSize: 3116 kB ==== test04.rb ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-linux] VmSize: 2976 kB VmSize: 2976 kB ruby 1.8.6 (2008-07-03 patchlevel 265) [i686-linux] VmSize: 2988 kB VmSize: 2988 kB meaning HEAD from ruby_1_8_6 does not leak after applying your patch. thanks! -- Rolando Abarca M.