Memory leak in ruby or dumb mistake?

Hi, I’ve narrowed down a memory leak in my program to the extremely
simple C extension at:

http://PATH.Berkeley.EDU/~vjoel/Task.tgz

Can anyone see anything I’m doing wrong?

The heart of the problem seems to be in calling the following method,
Task#read, repeatedly, from an eval:

VALUE read_module_Task_method(VALUE self)
{
Task_Shadow *shadow;
Data_Get_Struct(self, Task_Shadow, shadow);

 free(shadow->value);
 shadow->value = 

strdup(“foobar----------------------------------------”);

 return Qnil;

}

Oh, forgot to say I’m using a recent 1.9.0 snapshot:

$ ruby -v
ruby 1.9.0 (2004-03-09) [i686-linux]

Try str = nil before the second GC.start in your task.rb. :wink:

···

On Wed, 2004-03-17 at 03:26, Joel VanderWerf wrote:

Hi, I’ve narrowed down a memory leak in my program to the extremely
simple C extension at:


="puts’=‘+.inspect+‘;’+";puts’='+.inspect+‘;’+_

Hmm, this also leaks, so at least you didn’t make a mistake:

def sz
ps v.split(“\n”).grep(/#{$0}/)[0].split[7]
end

a = Array.new
str = “a.size\n” * 100000
GC.start
p sz
eval str
GC.start
p sz

···

On Wed, 2004-03-17 at 03:26, Joel VanderWerf wrote:

Hi, I’ve narrowed down a memory leak in my program to the extremely
simple C extension at:


="puts’=‘+.inspect+‘;’+";puts’='+.inspect+‘;’+_

Florian Frank wrote:

···

On Wed, 2004-03-17 at 03:26, Joel VanderWerf wrote:

Hi, I’ve narrowed down a memory leak in my program to the extremely
simple C extension at:

Try str = nil before the second GC.start in your task.rb. :wink:

Thanks, but that’s not the problem. The long string that ‘str’ refers to
is already reported the first time around, and the leak is the
difference between the first report and the second. The string is only
1Mb long, and the leak is around 8Mb.

Florian Frank wrote:

···

On Wed, 2004-03-17 at 03:26, Joel VanderWerf wrote:

Hi, I’ve narrowed down a memory leak in my program to the extremely
simple C extension at:

Hmm, this also leaks, so at least you didn’t make a mistake:

def sz
ps v.split(“\n”).grep(/#{$0}/)[0].split[7]
end

a = Array.new
str = “a.size\n” * 100000
GC.start
p sz
eval str
GC.start
p sz

Hm, interesting. Not an extension issue at all then.

Argh, you’re correct. Your sz call grepped my “vim task.rb” instead of
task.rb. I just found out that it worked only when I edited the file,
strange…

···

On Wed, 2004-03-17 at 04:20, Joel VanderWerf wrote:

Florian Frank wrote:

On Wed, 2004-03-17 at 03:26, Joel VanderWerf wrote:

Hi, I’ve narrowed down a memory leak in my program to the extremely
simple C extension at:

Try str = nil before the second GC.start in your task.rb. :wink:

Thanks, but that’s not the problem. The long string that ‘str’ refers to
is already reported the first time around, and the leak is the
difference between the first report and the second. The string is only
1Mb long, and the leak is around 8Mb.


="puts’=‘+.inspect+‘;’+";puts’='+.inspect+‘;’+_

Florian Frank wrote:

Argh, you’re correct. Your sz call grepped my “vim task.rb” instead of
task.rb. I just found out that it worked only when I edited the file,
strange…

Now that I think of it, I should have used

ps -o rss,cmd

Or, better, found a ruby library to do it. Oh, well.