113 | | |
| 113 | You may come across examples that call the {{{Destroy()}}} method. [http://www.gis.usu.edu/~chrisg/python/2009/lectures/ospy_slides2.pdf This tutorial] even gives specific advice on page 12 about when to call {{{Destroy()}}}. But according to [http://lists.osgeo.org/pipermail/gdal-dev/2010-September/026027.html email from Even Rouault], {{{Destroy()}}} never needs to be called: |
| 114 | |
| 115 | {{{ |
| 116 | > I have some Python code that uses OGR geometry objects internally, creating |
| 117 | > them like this: |
| 118 | > |
| 119 | > point = ogr.Geometry(ogr.wkbPoint) |
| 120 | > |
| 121 | > Does this code need to explicitly destroy these geometries, like the |
| 122 | > following, to avoid leaks, or can it simply allow them to go out of scope |
| 123 | > and have Python's reference counting and garbage collector clean them up? |
| 124 | > |
| 125 | > point.Destroy() |
| 126 | |
| 127 | There's no reason to call Destroy(), at all. Native object gets destroyed when |
| 128 | Python object goes out of scope, or when they are assigned to None. So replace |
| 129 | foo.Destroy() by foo = None if you really want to control when the underlying |
| 130 | C++ object is destroyed. |
| 131 | |
| 132 | > I'm sorry for my ignorance here. I found a nice GDAL tutorial that seems to |
| 133 | > say they *should* be explicitly destroyed in certain circumstances (see |
| 134 | > http://www.gis.usu.edu/~chrisg/python/2009/lectures/ospy_slides2.pdf, page |
| 135 | > 12). But I have not really seen any other examples of this. |
| 136 | > |
| 137 | |
| 138 | Destroy() was perhaps necessary with old-gen bindings, but I'm not even sure |
| 139 | of that... Perhaps this shouldn't have been exposed at all... But, as |
| 140 | mentionned in the slides, it is true that there are situations where you |
| 141 | shouldn't call Destroy() at all. |
| 142 | }}} |