From: Tobias Peters Date: 2002-04-10T10:31:14+09:00 Subject: Re: C++ extensions, garbage collection, Ruby and SWIG On 8 Apr 2002, Phil Tomson wrote: > "Be sure to understand ruby's memory management before attempting to > design your classes. Since you want to write a "C++ extension to Ruby", > you should defer all memory management to the ruby interpreter." > - Tobias Peters > > That actually sounds like good advice, however the library I want to > 'swig' already has 'automated garbage collection' as a feature. Will this > cause trouble? Are there ways to work around the problems that might > be caused by this? Hi Phil, then you should seek to understand both memory management implementations and find a way to to have them working together in the same process. Sorry, I cannot give you more advice, since I don't know (and don't want to learn) how the buddy lib manages its memory. The easiest libraries to wrap are those with explicit reference counting, then you can just reference a c++ object when you wrap it in a ruby object and dereference it from free. Similar are C++ libraries that encapsulate their worker objects through smart pointers, which is just a way to hide reference counting from the application programmer in constructors and destructors. But with every other kind of library you are on your own. You have to examine which objects are managed by the library and which are supposed to be managed by the user, and when the ownership changes and such. Good luck, Tobias