[Gdal-dev] importFromWkt() problem
Petteri Packalen
packalen at cs.joensuu.fi
Tue Sep 5 15:13:31 EDT 2006
Mateusz, Frank and others,
> Are you running your code on Windows with DLLs? If you
> are, then may be you're dealing with "passing objects
> across DLL boundaries" issue.
I rewrote this part of the code using OGR C interface and now it works
perfectly using both approaches I presented previously. Probably it was
some sort of dll/heap issue. I use precompiled dll from FWTools under
Windows.
I also noticed that there was a substantial memory leak in my code. I was
creating new OGRSpatialReference within a loop which browses through
features:
while ( TRUE )
{
... // Create WKT
OGRSpatialReferenceH hRef = OSRNewSpatialReference( NULL ); // <---
OGRGeometryH hGeomNew;
OGRErr err = OGR_G_CreateFromWkt( &pszWkt, hRef, &hGeomNew );
OGR_F_SetGeometryDirectly( hDstFeature, hGeomNew );
OGR_L_CreateFeature( hDstLayer, hDstFeature )
OGR_F_Destroy( hDstFeature );
}
Thus I instantiated very many OGRSpatialReferences. When I instantiated
only one OGRSpatialReference out of the loop memory leak disappeared (or
alternatively passing directly NULL to OGR_G_CreateFromWkt as spatial
reference). I look at the source code and tried to trace why all of
OGRSpatialReferences are not de-allocated via ~OGRFeature() -->
~OGRGeometry() --> OGRSpatialReference::Release() but I didn't follow
without modifying source code (I use FWTools dll). Probably reference
counting in OGRSpatialReference cannot handle this kind of misuse of the
OGR?
Anyway, it was my mistake. I really appreciate your help in this list.
Best regards,
Petteri
=========================================================================
Petteri Packalén
University of Joensuu
Faculty of Forestry
P.O. Box 111
80101 Joensuu
Finland
e-mail: packalen at cs.joensuu.fi
=========================================================================
More information about the Gdal-dev
mailing list