Possible memory leak using dup and setting an unassigned instance variable (Windows)
- Run the following code (tested on Window 7):
class Leaky attr_accessor :v def leak; d = dup; d.v = nil; end end l = Leaky.new while true; l.leak; end
- Watch the memory usage in Task Manager or equivalent Expected result: Infinite loop, memory usage fairly stable (as GC cleans up)
Interpreter consumes more and more memory, and eventually throws the following exception: "in `dup': failed to allocate memory (NoMemoryError)." Presumably, this is a memory leak.
If you manually set the instance variable before dup-ing, memory usage is stable. Accordingly, this code does not appear to leak memory:
class NonLeaky attr_accessor :v def leak; @v ||= nil; d = dup; d.v = nil; end end l = NonLeaky.new while true; l.leak; end
Updated by nobu (Nobuyoshi Nakada) about 6 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
Applied in changeset r47372.
object.c: fix memory leak
- object.c (rb_obj_copy_ivar): allocate no memory for empty instance variables. [ruby-core:64700] [Bug #10191]
Updated by nagachika (Tomoyuki Chikanaga) about 6 years ago
- Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED to 2.0.0: REQUIRED, 2.1: DONE
r46501, r47372 and r47460 were backported into
ruby_2_1 branch at r47520.
I add limit: 2.5 option argment to assert_no_memory_leak in the testcase because it fails with default threshold (1.5) on 2.1.
Updated by usa (Usaku NAKAMURA) about 6 years ago
- Backport changed from 2.0.0: REQUIRED, 2.1: DONE to 2.0.0: DONE, 2.1: DONE
ruby_2_0_0 at r47548.
In my environment, I don't have to change the limit of assert_no_memory_leak.
I may change it if CIs report some problems.