|
From: Barry S. <ba...@ba...> - 2009-01-04 18:24:27
|
On 1 Jan 2009, at 23:56, William Newbery wrote:
> > In cases like this I use a pointer:
> >
> > Py::ExtensionObject<Input> *input_ptr;
> >
> > and new a Py::ExtensionObject<Input>( input ) when I have it
> available.
> >
> > You need to create the the Py::Object to pass it back to python like
> > this:
> >
> > Py::ExtensionObject<Input> an_input_object( Py::asObject( new
> > Input(this, hwnd) ) ) );
You are not use asObject...
>
> >
> > I've been looking at allowing Py::Object to hold NULL for V6.0.0 -
> but
> > that targeted at Python 3.0.
> >
> >
> > Barry
>
> Ok, I did as you said and used the Py::ExtensionObject, however I
> seem to be back where I started with object not being deleted :(
>
> The problem seems to be that somehow it thinks it still refrenced
> when its not, that is when I checked the refrence count before
> destroying what should be the final refrence it reports a count of
> 2. Whats more when the object is first created the count seems to
> start at 2...
>
> Where the object is created
> //create voice object
> Py::ExtensionObject<SourceVoice> voice(new
> SourceVoice(sourceVoice, Py::ExtensionObject<Sound>(this), loop));
You are not using Py::asObject...
>
> std::cout << voice.reference_count() << " ";//2???
I'd expect it to be 0 given the error with Py::asObject
Make the asObject change and see what you get.
>
> audio->extensionObject()->AddSourceVoice(voice);//the Audio
> class maintains a reference (basicly adds to playing set in Audio
> class)
> //start playback
> sourceVoice->Start(0);
>
> std::cout << voice.reference_count() << std::endl;//3, as
> exspected since refrence was 2 before
> return voice;//in my tests this return value was not used
> }
>
> The objects constructor - I see nothing here to create a 2nd
> refrence to itself, only an extra refrence to the Sound object
> SourceVoice::SourceVoice(IXAudio2SourceVoice *_voice,
> Py::ExtensionObject<Sound> _sound, bool _isLooping)
> :voice(_voice), isLooping(_isLooping), isPaused(false), sound(_sound)
> {}
If you print the ref count in the c'tor it should be 0.
Barry
|