logo       

Re: how to prevent objects from being garbage collected.: msg#00124

programming.swig

Subject: Re: how to prevent objects from being garbage collected.

On 2004.05.24 13:29, meinrad recheis wrote:
when ruby exits, all objects will be deleted and their C++ destructors get called. if objects that are owned by others (in C++) are deleted bevore their owners the owners will try to free them again and that leads to memory access errors.

how can i tell ruby to not call the destructor of certain objects??

Hi,
I think the real question is: how can you prevent Ruby and C++ from thinking they both own the object. Are the objects created on the C++ side and returned through a swigged function? In this case, the wrappers are generated so that Ruby knows it should'n call the destructor; therefore, you shouldn't have the problem. Instead, if objects are created on the Ruby side and passed to other objects who then take ownership and will take care to delete them, you should find a way to tell Ruby they're no longer owned, which might be a problem.
In this case, you could write a factory function and use that (instead of their constructors) to instantiate your objects. This way you would return to the first case (object returned from C++, Ruby knows not to delete it.)

Later,
Luigi
_______________________________________________
Swig maillist - Swig@xxxxxxxxxxxxxxx
http://mailman.cs.uchicago.edu/mailman/listinfo/swig



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise