From: Paul Brannan Date: 2002-04-10T22:57:25+09:00 Subject: Re: C++ extensions, garbage collection, Ruby and SWIG On Wed, Apr 10, 2002 at 10:30:29AM +0900, Phil Tomson wrote: > 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? I don't know how swig will deal with languages that do not have their own garbage collection, but for Ruby, swig uses Ruby's built-in garbage collection (but it abstracts all this away so you don't have to think about it much). The only cases I have found where garbage collection was an issue with swig were: 1) I needed to callback into Ruby code, so I passed in a VALUE directly to my C++ code. I stored a reference to this VALUE, so I had to mark it. 2) I have some odd typemaps that need to be aware of Ruby's GC. I think that most typemaps do not (it has to do with wrapping CORBA objects and adding/removing references; the code is buried somewhere, so please don't ask for an example). 3) When writing my exception handler (using swig's %except), I needed to know that Ruby uses longjmp for exceptions, and that this would interfere with cleanup of any C++ exceptions. I can use the Ruby GC, though, to ensure proper cleanup (or I can do this in C++ with an extra try/catch). Perhaps Lyle can come up with a couple more cases. Paul