Need help with memory consumption

OS: Windows.

I wrote a DLL which itself uses the Ruby (1.6.8) DLL.

My DLL creates some objects, loads a script, calls some functions in the
script and destroys the object again. Should be neutral to memory
consumption. When I issue “ObjectSpace.each_object(Object) {}”, I always get
the same value (±5 objects). I call the GC regularly.

Problem is, that when I do that procedure (create an object, call the script
functions) multiple times, that the “VM Size” of the process increases more
and more.

Background: my DLL is a plugin for the spam fighting tool “SpamPal”, and I
use Ruby to process the mails. I create a "CMail’ object, and for each mail
I create an instance and call the spam-testing functions. And when I have
filtered about 1000 mails, VM Size has grown to 400 MB and the computer runs
out of virtual memory and crashes.

Is there a problem known, or any way to find the cause?

I would call myself an experienced programmer and I am pretty sure that the
memory is NOT used by my DLL, but from the Ruby DLL (which is more or less a
black box for me).

I create objects using:
VALUE vMail = RUBYFUNC(rb_define_class)(“CMail”,*RUBYFUNC(rb_cObject));

RUBYFUNC(rb_define_singleton_method)(vMail,“new”,RB_METHOD(clsMail::alloc),0
);
… define some methods
_vMail = _Ruby.Call(vMail, RUBYFUNC(rb_intern)(“new”), 0);
RUBYFUNC(rb_gc_register_address)(&_vMail);

and release them by

RUBYFUNC(rb_gc_unregister_address)(&_vMail);

I would assume that to allow the GC to destroy the objects afterwards,
correct? Wouldn’t the “ObjectSpace.each_object(Object) {}” increase if I
were leaking objects?

Thanks for any help I can get!

Christian

Okay, I must correct myself: the count of objects increases.

How can I tell the GC it can free my object, then?

When I put a finalizer on the objects, it’s not called unless I call
ruby_cleanup() or ruby_finalize(). So definitely the object is kept in
memory.

So my problem is: I create an object in my C++ code, which is passed to the
scripts, and how can I tell the GC that this object is not needed any more
and can be freed? I’m sure there’s no refernce to the object in the script.

Example:

in C++:

VALUE vMail = rb_define_class("CMail",*RUBYFUNC(rb_cObject));
rb_define_singleton_method(vMail,"new",RB_METHOD(clsMail::alloc),0);
... define some methods
_vMail = _Ruby.Call(vMail, rb_intern("new"), 0); // rb_protect around

rb_funcall2()…
rb_gc_register_address(&_vMail);

call a script function with _vMail as argument
_Ruby.Call(rb_cObject, rb_intern(“checkTheMail”),1,_vMail);

in the script:

def checkTheMail(mail)
… do something with mail
end

and in C++ again:

rb_gc_unregister_address(&_vMail);

Now I would expect that my mail object could be garbage collected - but it
is not. Any ideas welcome.

Christian

“Christian Kaiser” chk@online.de wrote in message
news:c92pl1$l7d$1@online.de

OS: Windows.

I wrote a DLL which itself uses the Ruby (1.6.8) DLL.

My DLL creates some objects, loads a script, calls some functions in the
script and destroys the object again. Should be neutral to memory
consumption. When I issue “ObjectSpace.each_object(Object) {}”, I always
get
the same value (±5 objects). I call the GC regularly.

Problem is, that when I do that procedure (create an object, call the
script
functions) multiple times, that the “VM Size” of the process increases
more
and more.

Background: my DLL is a plugin for the spam fighting tool “SpamPal”, and I
use Ruby to process the mails. I create a "CMail’ object, and for each
mail
I create an instance and call the spam-testing functions. And when I have
filtered about 1000 mails, VM Size has grown to 400 MB and the computer
runs
out of virtual memory and crashes.

Is there a problem known, or any way to find the cause?

I would call myself an experienced programmer and I am pretty sure that
the
memory is NOT used by my DLL, but from the Ruby DLL (which is more or less
a
black box for me).

I create objects using:
VALUE vMail =
RUBYFUNC(rb_define_class)(“CMail”,*RUBYFUNC(rb_cObject));

RUBYFUNC(rb_define_singleton_method)(vMail,“new”,RB_METHOD(clsMail::alloc),0

···

);
… define some methods
_vMail = _Ruby.Call(vMail, RUBYFUNC(rb_intern)(“new”), 0);
RUBYFUNC(rb_gc_register_address)(&_vMail);

and release them by

RUBYFUNC(rb_gc_unregister_address)(&_vMail);

I would assume that to allow the GC to destroy the objects afterwards,
correct? Wouldn’t the “ObjectSpace.each_object(Object) {}” increase if I
were leaking objects?

Thanks for any help I can get!

Christian