[C++-sig] PyObject RefCount

Renato Araujo renatox at gmail.com
Wed Dec 3 19:04:31 CET 2008


Hi all,

I'm trying check  if have someone using my object in python, but I got
some problems I think I'm not doing this in the correct way:

I have a function like that:

voi MyClass::~MyClass()
{
    for(int i=0; i < childCount(); i++)
    {
        BaseClass *child = child_at(i);

        python::object py_obj(pyhton::ptr(child));  //I can't this
without ptr because my object no have copy constructor
        //Whats happen here??  ^^^
                  - How this work when the object already exists? and
whats happen when the object not exists?
                  - There is a better way to verify if already have a
python object associate with my child c++ object?

        if (py_obj.ptr()->ob_refcnt == 1)
             delete child;
         else
          {
              //do nothing python GC will destroy this
           }
     }
}

How I can fix this?? How is the best way to do this?

Thanks


-- 
Renato Araujo Oliveira Filho


More information about the Cplusplus-sig mailing list