From: Barry S. <ba...@ba...> - 2008-12-18 19:47:00
|
On 15 Dec 2008, at 20:58, William Newbery wrote: > For some reason the python extension object is not deleted when > finished with. It is python that causes the delete when the ref count hits zero. You are bypassing python when you modify ob_refcnt. For the automatic ref count handling you have to put your C++ objects into a Py::Object. Look at Demo/rangetest.cpp for examples of using Py::ExtensionObject. > > > //clear up finished sounds > for(std::vector<SourceVoice*>::iterator it=finished.begin();it! > =finished.end();++it) > { > playing.erase(*it); > (*it)->ob_refcnt--;//remove the refrence we added when we > got the voice Must not touch the ref cnt it is only to be done by python code via its API or via PyCXX that uses the python API. > > std::cout << "finished voice refrence: " << (*it)->ob_refcnt > << std::endl; //prints 0 > } > > class SourceVoice : public Py::PythonExtension<SourceVoice> > { > IXAudio2SourceVoice *voice; > Sound *sound; Use: Py::ExtensionObject<Sound> sound; > public: > static void init_type(); > SourceVoice(IXAudio2SourceVoice *voice, Sound *sound); > virtual ~SourceVoice(); > > IXAudio2SourceVoice *GetVoice(){return voice;} > private: > Py::Object GetVolume(const Py::Tuple &args); > Py::Object SetVolume(const Py::Tuple &args); > Py::Object Stop (const Py::Tuple &args); > Py::Object ExitLoop (const Py::Tuple &args); > }; > > SourceVoice::SourceVoice(IXAudio2SourceVoice *_voice, Sound *_sound) > :voice(_voice), sound(_sound) > { > sound->ob_refcnt++; Need to pass in a Py::Object for _sound. > } > SourceVoice::~SourceVoice()//not called > { > std::cout << "voice destroyed" << std::endl; > sound->ob_refcnt--; when Py::ExtensionObject d'tor is called it will drop the ref cnt for you. > > voice->DestroyVoice(); > } > > Is there some reason why an object is not deleted even when the > refcnt hits zero, in fact the objects are not even getting deleted > when the python program ends, leaving windows to clear up 100's of > MB's of sound data... Barry |