title: Boost.Python: Ownership of pointer variables
body: <p>I'm exposing a C++ tree class using Boost.Python to python. The node class holds a list of child nodes and provides a method </p>
  
  <pre><code>void add_child(Node *node)
  </code></pre>
  
  <p>The Node class takes ownership of the provided Node pointer and deletes it's child nodes when the destuctor gets called.</p>
  
  <p>I'm exposing the add_child method as:</p>
  
  <pre><code>.def("addChild", &amp;Node::add_child)
  </code></pre>
  
  <p>My actual question is: How do i tell Boost.Python that the Node class takes ownership of the child nodes?</p>
  
  <p>Because if i execute the following code in python:</p>
  
  <pre><code>parentNode = Node()
  node = Node()
  parentNode.addChild(node)
  </code></pre>
  
  <p>the object referenced by the node variable gets deleted twice at the end of the script. Once when the node variable gets deleted and a second time when the parentNode gets deleted.</p>