[bug] serious memory leak + continuations

Hi,

ruby 1.9.0 (2004-12-20) [i386-freebsd5.2.1]
gcc version 3.3.3 [FreeBSD] 20031106

In my application, if I change:

# (1) this works
callback_stream.with_callbacks_for(self, :action) { |callback, val|
   catch(:something) { callback.call }
   throw :wee_back_to_session
 }

into:

# (2) this leaks
callback_stream.with_callbacks_for(self, :action) { |callback, val|
   res = catch(:something) { callback.call }
   throw :wee_back_to_session
 }

or into:

 # (3) this leaks
 callback_stream.with_callbacks_for(self, :action) { |callback, val|
   callback.call
   throw :wee_back_to_session
 }

memory consumption is unbounded! BTW, “:something” is never thrown. It
seems that if I reference the return value of callback.call, the memory
leak appears. The leak also happens if I change “res = " in (2) into
@res = " or "$res = ". Note that inside callback.call continuations are
created.

And if I return “nil” from the block (callback.call), it leaks, too,
even if I use code sample (1).

I tried above example also with ruby-stable compiled with 2.95.4 (-O0
enabled), but there all three examples leak memory.

It seems to be related to the “unknown node type 0 bug”, as it appears
to be pretty random (at least in my eyes):

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/123694

Help! I can send the whole sources to someone who is interested. Only
requirements are rubygems, installed narf gem (webunit) and gnuplot to
display memory consumption, and of course *nix.

Regards,

Michael

Michael Neumann wrote:

Hi,

ruby 1.9.0 (2004-12-20) [i386-freebsd5.2.1]
gcc version 3.3.3 [FreeBSD] 20031106

In my application, if I change:

(1) this works

callback_stream.with_callbacks_for(self, :action) { |callback, val|
catch(:something) { callback.call }
throw :wee_back_to_session
}

into:

(2) this leaks

callback_stream.with_callbacks_for(self, :action) { |callback, val|
res = catch(:something) { callback.call }
throw :wee_back_to_session
}

or into:

# (3) this leaks
callback_stream.with_callbacks_for(self, :action) { |callback, val|
  callback.call
  throw :wee_back_to_session
}

memory consumption is unbounded! BTW, “:something” is never thrown. It
seems that if I reference the return value of callback.call, the memory
leak appears. The leak also happens if I change "res = " in (2) into
"@res = " or "$res = ". Note that inside callback.call continuations are
created.

And if I return “nil” from the block (callback.call), it leaks, too,
even if I use code sample (1).

I tried above example also with ruby-stable compiled with 2.95.4 (-O0
enabled), but there all three examples leak memory.

It seems to be related to the “unknown node type 0 bug”, as it appears
to be pretty random (at least in my eyes):

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/123694

Help! I can send the whole sources to someone who is interested. Only
requirements are rubygems, installed narf gem (webunit) and gnuplot to
display memory consumption, and of course *nix.

The memory leak probably results from the fact that the continuations
are not garbage collected. The number of them keep growing in (2) and
(3), whereas in (1) it stays constant.

Regards,

Michael