[geos-devel] Object Destruction
thilo.fischer at ksti.de
thilo.fischer at ksti.de
Tue Oct 27 04:48:45 PDT 2015
Hello,
to my understanding, one should always delete/free heap memory allocations
with the same mechanism and in the same context as used to allocate the
memory. E.g. don't mix C's malloc with C++'s delete or C++'s new with C's
free on the same object. For this reason, I always use
myGeosGeometry->getFactory()->destroyGeometry(myGeosGeometry);
instead of
delete myGeosGeometry;
This looks a little odd, but after some googling this was the best
approach I could find to destroy GEOS Geometry objects properly.
Now I need to delete a CoordinateSequence, and could not find any
appropriate destroy function to do so. destroyGeometry won't work because
CoordinateSequence is not a child class of Geometry.
After some googling, the only thing I found on this topic was this
http://trac.osgeo.org/geos/ticket/325 wontfix-closed task from 2008. This
mailing-list discussion thread
https://lists.osgeo.org/pipermail/geos-devel/2008-August/thread.html#3437
addressed the same issue, but for a different class (PreparedGeometry). As
Mateusz and his referenced FAQ entry from the GDAL wiki point out, one
might get serious trouble on Windows systems when reserving and deleting
heap allocations inconsistently. I guess this would have been the point
why to expose such interface that was not seen when closing #325 wontfix :(
Is it that a destroy function for CoordinateSequence is missing in GEOS
(is it a bug?), or did I fail to notice some detail in the GEOS API which
solves this issue? Is
myGeosGeometry->getFactory()->destroyGeometry(myGeosGeometry) the intended
way to delete Geometry objects?
Thank, best regards
Thilo Fischer
More information about the geos-devel
mailing list