[Qgis-developer] Object owner design in QgsGraphBuilder

Kuhn Matthias, Vermessung Matthias.Kuhn at Stadt-Uster.ch
Thu Aug 23 05:47:06 PDT 2012


Hi

I've recently been working with the network analysis library.
 
When I had a look at the code I noticed the following:
 
In the constructor a new QgsGraph() mGraph is instantiated
In the destructor mGraph is deleted if not null
In the method graph() mGraph is returned and set to null
 
This leads to the effect, that if I request the graph() from the QgsGraphBuilder ( and I normally will, as that's the only purpose of using the QgsGraphBuilder ) I get the full ownership and have to delete the graph-object, when I'm finished with it. But this is not stated in the API. So without looking at the code there is no way to know this.
 
- How does python handle this? Does the following code delete this object?

graph = graphBuilder.graph()
graph = null

- In my opinion, this is a wrong design. I would rather pass a graph-object to the graphbuilder in the constructor and let it fill this object. Then I know, that is my responsibility to delete it afterwards.
 
I would provide a patch to change this if there are no good reasons to keep it the way it is.
 
Regards,
Matthias


More information about the Qgis-developer mailing list