Here's some info about refcounting... it looks like we need to explore
%refcount and %unrefcount
Monty
-------- Original Message --------
Subject: Re: [Swig-user] C++ wrapping question
Date: Sun, 29 Apr 2007 08:28:40 +0100
From: William S Fulton <wsf@stripped>
To: Monty Taylor <monty@stripped>
CC: swig-user@stripped
References: <462E8B3E.3040704@stripped>
Monty Taylor wrote:
> Hey guys,
>
> I've got a question I'm trying to figure out... I'm wrapping some C++
> classes that I can't change.
>
> I've got two classes, for sake of simplicity, here abbreviated:
>
> %newobject Ndb::startTransaction;
> class Ndb {
> public:
> NdbTransaction * startTransaction();
> void closeTransaction(NdbTransaction *);
> };
>
> class NdbTransaction {
> NdbTransaction();
> ~NdbTransaction();
> public:
> close();
> };
>
> As you can probably guess, startTransaction allocates and returns a new
> NdbTransaction. Ndb manages the life of the NdbTransaction, so I added
> %newobject to indicate this to swig.
>
> When the wrapper object gets deleted, I'd like to ensure that either
> NdbTransaction::close() or Ndb:closeTransaction are called. I'm assuming
> (haven't looked all the way at the code) that the wrapped object can be
> garbage collected in the wrapping language without trying to delete the
> wrapped object - which is the idea with the %newobject, right?
>
> So is there a way to hook in to the wrapper object destruction?
>
Yes. The %unrefobject directive which is the "unref" feature can do this
for you. Use it to call the destructor plus any other code you want. See
Examples/test-suite/refcount.i for an example and look for unref in the
CHANGES file for some docs.
William
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Swig-user mailing list
Swig-user@stripped
https://lists.sourceforge.net/lists/listinfo/swig-user
--
Monty Taylor
Senior Consultant
MySQL Inc., www.mysql.com
Get More with MySQL! www.mysql.com/consulting