[Qgis-developer] Object owner design in QgsGraphBuilder

Matthias Kuhn matthias.kuhn at gmx.ch
Fri Aug 24 00:32:52 PDT 2012


Just figured out that the sip option /Factory/ tells python that it
takes ownership of this object. So there won't be any memory loss. I'd
still say this should be changed and if not at least stated in the API
so anybody using this in C++ will be aware of this without reading the
code.

On Thu, 2012-08-23 at 12:47 +0000, Kuhn Matthias, Vermessung wrote:
> 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
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer




More information about the Qgis-developer mailing list