Try to post the smallest complete interface file and script that
demonstrates the problem, and then the answer may be more obvious.
Thanks for the reply and the comment about auto_ptr. I'll be using
that. As for the smallest complete example:
//-------------------------------------------------------------------
// thingy.h
//-------------------------------------------------------------------
#include <iostream>
using namespace std;
class Thingy {
public:
Thingy() {
_number = ++number;
cout << "Thingy " << _number << " constructed.\n";
}
~Thingy() {
cout << "Thingy " << _number << " destructed.\n";
}
Thingy * add(Thingy *other) {
return new Thingy();
}
static int number;
protected:
int _number;
};
//-------------------------------------------------------------------
// thingy.cxx
//-------------------------------------------------------------------
#include "thingy.h"
int Thingy::number = 0;
//-------------------------------------------------------------------
// thingy.i
//-------------------------------------------------------------------
%module thingy
%{
#include "thingy.h"
%}
%include "thingy.h"
//-------------------------------------------------------------------
// irb output (slightly trimmed):
//-------------------------------------------------------------------
> require 'thingy.so'
> a = Thingy::Thingy.new
Thingy 1 constructed.
> b = Thingy::Thingy.new
Thingy 2 constructed.
> c = a.add(b)
Thingy 3 constructed.
irb(main):005:0> a,b,c, = 0,0,0
irb(main):006:0> GC.start
Thingy 2 destructed.
Thingy 1 destructed.
As you can see. Thingy 3 does not get destructed. I tried changing
the function add to
void add(Thingy *other, Thingy *OUTPUT) {
OUTPUT = new Thingy();
}
and include "typemaps.i" in the thingy.i file as (sort of) is
suggested in the swig documentation but that does not work.
best regards,
Richard