Project

General

Profile

Actions

Bug #10191

closed

Possible memory leak using dup and setting an unassigned instance variable (Windows)

Added by benhell (Ben Hellerstein) over 9 years ago. Updated over 9 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
1.9.3p327 (2012-11-10) [i386-mingw32] (also present in 2.0.0p481 [i386-mingw32] from rubyinstaller.org)
[ruby-core:64700]

Description

Steps:

  1. 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
  1. 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:

class NonLeaky
  attr_accessor :v
  def leak; @v ||= nil; d = dup; d.v = nil; end
end

l = NonLeaky.new
while true; l.leak; end
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0