有生就有死,既然有了singleton对象GDALDriverManger,就要在main函数退出之前销毁它。
前文GDAL singleton的经典错误 已经分析了这是DCLP的模式,最后由一个指针poDM指向被创建出来的唯一的对象。因为是new出来的,自然要找到delete的地方。同样在gdaldrivermanager.cpp文件,在最后的位置,提供了函数GDALDestroyDriverManager用来完成最后的清理工作。 注释提醒,不要在其他线程还在使用GDAL内部的对象时调用该函数。我只会在退出前调用。
/**
* \brief Destroy the driver manager.
*
* Incidently unloads all managed drivers.
*
* NOTE: This function is not thread safe. It should not be called while
* other threads are actively using GDAL.
*/
void CPL_STDCALL GDALDestroyDriverManager( void )
{
// THREADSAFETY: We would like to lock the mutex here, but it
// needs to be reacquired within the destructor d