From: nobu@... Date: 2014-09-03T07:56:20+00:00 Subject: [ruby-core:64734] [ruby-trunk - Bug #10191] [Closed] Possible memory leak using dup and setting an unassigned instance variable (Windows) Issue #10191 has been updated by Nobuyoshi Nakada. 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] ---------------------------------------- Bug #10191: Possible memory leak using dup and setting an unassigned instance variable (Windows) https://bugs.ruby-lang.org/issues/10191#change-48627 * Author: Ben Hellerstein * Status: Closed * Priority: Normal * Assignee: * Category: * Target version: * ruby -v: 1.9.3p327 (2012-11-10) [i386-mingw32] (also present in 2.0.0p481 [i386-mingw32] from rubyinstaller.org) * Backport: 2.0.0: REQUIRED, 2.1: REQUIRED ---------------------------------------- Steps: 1. Run the following code (tested on Window 7): ~~~ruby class Leaky attr_accessor :v def leak; d = dup; d.v = nil; end end l = Leaky.new while true; l.leak; end ~~~ 2. Watch the memory usage in Task Manager or equivalent Expected result: Infinite loop, memory usage fairly stable (as GC cleans up) Actual result: 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. Workaround: If you manually set the instance variable before dup-ing, memory usage is stable. Accordingly, this code does not appear to leak memory: ~~~ruby class NonLeaky attr_accessor :v def leak; @v ||= nil; d = dup; d.v = nil; end end l = NonLeaky.new while true; l.leak; end ~~~ -- https://bugs.ruby-lang.org/