The PyHandler class This class is the base class of all Lexocad classes which exports into the python space. This class handles the creation referencing of the python export object.
E.g. if GetPyObject() always returns a new Python object then no increment is necessary, because at construction time the reference counter is already set to 1. If the Python interpreter stores this object pointer into a local variable and destroys this variable then the reference counter gets decremented (to 0) and the object gets destroyed automatically. In case we didn't make this specification and increment the Python object from outside once again then the reference counter would be set to 2 and there would be no chance to destroy the object again.
The other case is that we have a member variable in our C++ class that holds the Python object then we either can create this Python in the constructor or create it the first time when GetPyObject() gets called. In the destructor then we must decrement the Python object to avoid a memory leak while GetPyObject() then increments the Python object everytime it gets called.
- Note
- To not to undermine this specification the programmer must make sure to get the Python object always via GetPyObject().
- See also
- PyHandle @