[FWTools] OGRFeature memory problem?

Frank Warmerdam warmerdam at pobox.com
Mon May 15 09:47:07 EDT 2006

Mike Toothaker wrote:
> Hello,
> I will start off by apologizing for my lack of geospatial knowledge.  I 
> have just started a project and I am trying
> to get caught up on the geospatial stuff as quickly as I can while 
> working with it.  We are using gdal in our project
> and I have the following code(almost an exact copy paste from the gdal 
> website).
>         delete poFeature;           //ß--- Error here


Due to what I consider a brain-dead approach to DLLs it is common for
microsoft applications to have distinct heaps for different DLLs.  This
means that you can't delete an object allocated in a different DLL unless
you take great care to ensure you are using the same heap.  I normally build
everything with /MD so all modules use the same MSVCRT.DLL for memory
allocation (hence one heap).

However, that is not always possible.  To be on the safe side you should
instead delete your features using:

  OGRFeature::DestroyFeature( poFeature );

Should you find yourself needing to dynamically create  feature I would
suggest using:

  poFeature = OGRFeature::CreateFeature( poFeatureDefn );

Some other classes and factories have similar static constructor/descructor
methods that should be used in preference to direct use of new and delete.

I *hate* this issue.

If you let me know exactly where what web page on the web site you worked
from, I'll change it to use OGRFeature::DestroyFeature().

PS. This sort of GDAL specific development issue might be better posed on
gdal-dev.  I generally think of the FWTools list as a place for FWTools
specific packaging issues, and high level user questions.

Best regards,
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGF, http://osgeo.org

More information about the FWTools mailing list