I use the following regular expression in the ActiViz .NET C# wrappers to determine what methods of VTK are "factory methods."<br><br>  "^(CreateImageReader2|CreateInstance|MakeTransform|New|NewInstance)$"<br>
<br>(seen in action in this file: <a href="http://public.kitware.com/gitweb?p=activizdotnet.git;a=blob;f=MummySettings.xml.in;h=786b24431b7fc75749c1ebb16840757857cfff13;hb=HEAD">http://public.kitware.com/gitweb?p=activizdotnet.git;a=blob;f=MummySettings.xml.in;h=786b24431b7fc75749c1ebb16840757857cfff13;hb=HEAD</a> )<br>
<br>Perhaps I need to extend it to include CreateArray as well?<br><br>Does anybody know of any others?<br><br><br>HTH,<br>David<br><br><br><div class="gmail_quote">On Tue, Apr 26, 2011 at 4:08 PM, David Gobbi <span dir="ltr"><<a href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Hi Tim,<br>
<br>
All NewInstance() methods are wrapped the same way.  There isn't any<br>
hinting mechanism to tell the wrappers that a new instance is being<br>
created.  In fact the only way even a human programmer can tell is by<br>
reading the documentation.<br>
<br>
Since instance-creation methods are rare in VTK, I would be<br>
comfortable hard-coding the few that exist into the wrappers.  For<br>
instance, any method called NewInstance that returns an object can be<br>
assumed to return a new instance (because honestly, why else would a<br>
method have such a name?).<br>
<br>
As a temporary and very dirty fix, you can use SetReferenceCount() to<br>
avoid the memory leaks.<br>
<font color="#888888"><br>
 - David<br>
</font><div><div></div><div class="h5"><br>
On Tue, Apr 26, 2011 at 1:39 PM, Timothy Shead <<a href="mailto:tshead@sandia.gov">tshead@sandia.gov</a>> wrote:<br>
><br>
> I'm troubleshooting a reference-counting issue in the Python bindings for VTK - in a nutshell, the only way to instantiate vtkArray-derived classes from Python is through the vtkArray::CreateArray() static factory method (because vtkArray derivates are template classes).<br>

><br>
> However, using vtkArray::CreateArray() from Python returns objects that have a reference-count of 2, because the Python wrapping code increments the reference-count of objects returned from "normal" class methods. This leads to annoying leaks when the program ends.<br>

><br>
> From what I can see, there's a separate code path when instantiating VTK objects from Python.  I'm thinking that there must be other examples of factory methods in VTK, and that there must be some clean way of using them from Python?<br>

><br>
> Thanks in advance,<br>
> Tim<br>
><br>
><br>
> --<br>
> Timothy M. Shead<br>
> Sandia National Laboratories<br>
> 1461, Scalable Analysis and Visualization<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtk-developers" target="_blank">http://www.vtk.org/mailman/listinfo/vtk-developers</a><br>
<br>
</div></div></blockquote></div><br>