[gdal-dev] Problem closing VRT GDALDataset *
Even Rouault
even.rouault at mines-paris.org
Tue Jul 21 17:55:15 EDT 2009
Le Tuesday 21 July 2009 22:50:10 Adeel Raza, vous avez écrit :
> Hi Frank,
>
> OK - my next question then is: If I close the VRT dataset if it
> references the MEM dataset using GDALClose(), would that operation also
> close the MEM dataset
It depends if you drop the reference on the MEM dataset before or after
closing the VRT.
GDALAutoCreateWarpedVRT() took an extra reference on the MEM dataset, so the
GDALClose() on this VRT will drop the extra reference on the MEM dataset. If
there's no more reference on it, it will be closed, otherwise you'll have to
do it yourself afterwards
> or would I need to close the MEM dataset after I
> close the VRT dataset?
The order of closing doesn't matter provided you do as Frank suggested before.
So you can use safely one of the 2 below possible solutions :
hMemDS = GDALCreate(...);
hVRTDS = GDALAutoCreateWarpedVRT(hMEMDS, ...) ; // now refcount(hMemDS) == 2
if( GDALDereferenceDataset(hMemDS ) == 0 ) // now refcount(hMemDS) == 1
GDALClose( hMemDS ); // won't be executed in fact
GDALClose(hVRTDS); // will drop the remaining ref on hMemDS and take care of
closing it
or invert the order of the last 2 operations :
hMemDS = GDALCreate(...);
hVRTDS = GDALAutoCreateWarpedVRT(hMemDS, ...) ; // now refcount(hMemDS) == 2
GDALClose(hVRTDS); // now refcount(hMemDS) == 1
if( GDALDereferenceDataset(hMemDS ) == 0 ) // now refcount(hMemDS) == 0
GDALClose( hMemDS ); // will be executed
>
> Best Regards,
> Adeel.
>
> Frank Warmerdam wrote:
> > Adeel Raza wrote:
> >> Hi Frank,
> >>
> >> Thanks for the help. It seems like you were correct. When I
> >> dereference the MEM dataset the post-decrement reference count is not
> >> 0. My question is: do I not close the MEM dataset since its reference
> >> count is not 0?
> >
> > Adeel,
> >
> > You should not be closing the MEM dataset while it is still referenced
> > by the VRT dataset.
> >
> > Best regards,
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
More information about the gdal-dev
mailing list