Changes between Version 2 and Version 3 of PythonGotchas

Sep 20, 2010, 9:16:08 AM (10 years ago)



  • 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.
    109 The examples here are based on [ email from Even Rouault].
     109The examples above are based on [ email from Even Rouault].
    111111=== Certain objects contain a {{{Destroy()}}} method, but you should never use it ===
     113You may come across examples that call the {{{Destroy()}}} method. [ This tutorial] even gives specific advice on page 12 about when to call {{{Destroy()}}}. But according to [ email from Even Rouault], {{{Destroy()}}} never needs to be called:
     116> I have some Python code that uses OGR geometry objects internally, creating
     117> them like this:
     119> point = ogr.Geometry(ogr.wkbPoint)
     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?
     125> point.Destroy()
     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.
     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>, page
     135> 12). But I have not really seen any other examples of this.
     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.
    115144= Gotchas fixed in GDAL 1.8.0 =