Changes between Version 2 and Version 3 of PythonGotchas


Ignore:
Timestamp:
Sep 20, 2010, 9:16:08 AM (14 years ago)
Author:
jjr8
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • PythonGotchas

    v2 v3  
    107107The advantage of the "Ref" and "Directly" functions is they provide faster performance because a duplicate object does not need to be created. The disadvantage is that you have to watch out for this problem.
    108108
    109 The examples here are based on [http://lists.osgeo.org/pipermail/gdal-dev/2010-September/026027.html email from Even Rouault].
     109The examples above are based on [http://lists.osgeo.org/pipermail/gdal-dev/2010-September/026027.html email from Even Rouault].
    110110
    111111=== Certain objects contain a {{{Destroy()}}} method, but you should never use it ===
    112112
    113 
     113You 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
     127There's no reason to call Destroy(), at all. Native object gets destroyed when
     128Python object goes out of scope, or when they are assigned to None. So replace
     129foo.Destroy() by foo = None if you really want to control when the underlying
     130C++ 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
     138Destroy() was perhaps necessary with old-gen bindings, but I'm not even sure
     139of that... Perhaps this shouldn't have been exposed at all... But, as
     140mentionned in the slides, it is true that there are situations where you
     141shouldn't call Destroy() at all.
     142}}}
    114143
    115144= Gotchas fixed in GDAL 1.8.0 =