[Gdal-dev] Memory leak under Matlab (a follow up from - importFromWkt() problem)

Joaquim Luis jluis at ualg.pt
Mon Sep 11 16:40:09 EDT 2006


Philip Borghesani wrote:
> It is not always simple or straight forward to translate from a properly 
> working main to a mex function.  In the example code you supplied I am 
> concerned about some of the initialization code that the tested example you 
> linked to is not doing in a while loop.
>
> Remember that a mex file is not unloaded after each call so you code is 
> doing the equvilent of putting a loop around a main function.
>
> Try placeing the initiization code in a block that will only run once:
>
> // untested code
>
>  static  OGRSFDriver *poDriver = NULL;
>
> if (poDriver==NULL) {
>     OGRRegisterAll();
>
>     // Driver
>     poDriver 
> =OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(pszDriverName);
>     assert(NULL != poDriver);
> }
>
> // I do not see any code that deletes or releases the poDriver is this 
> needed

Hi,
I received the mail above from the Mathworks.
I did what Philip Borghesani suggested without any advance. That is the 
memory leak still leaks.
However, I would like to be 100% sure in the answer to the second question.

Is the poDriver automatically freed?

Thanks

Joaquim Luis




More information about the Gdal-dev mailing list