[gdal-dev] Memory loss with RasterIO

Goo Creations goocreations at gmail.com
Fri May 27 05:47:00 EDT 2011


Hi all, I've come across some weird memory loss:

*uint *data = new uint[region->width*region->height];
int x = 0, y = 0;
dataset->GetRasterBand(band)->RasterIO(GF_Read, x, y, width, height, data,
width, height, GDT_UInt32, 0, 0);
delete [] data;
*

This code is executed a few thousand times with different x and y. After
doing this, 1.5GB memory was still used by my app. I'm using Ubuntu, and
apparently the linux kerenl manages memory differently, by not always
returning all freed memory to the OS, but rather keeping it for future use
by the application.
This is not the case here, since when allocating memory after the above
action, the freed memory is not reused. I've tried valgrind for proof, but
it crashes, since I'm using too much memory, and valgrind can't handle it.

When I change the above code to:

*uint *data = new uint[region->width*region->height];
int x = 0, y = 0;
//dataset->GetRasterBand(band)->RasterIO(GF_Read, x, y, width, height, data,
width, height, GDT_UInt32, 0, 0);
delete [] data;
*

so effectively removing the read-statement, all memory is freed and
returned. If also tried CPLMalloc and CPLFree,

The only way to get the memory release, is to close the dataset after all
the reads. Is this a bug, or was/is GDAL designed only to release the memory
after the dataset was close?

Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20110527/8af2dcd6/attachment.html


More information about the gdal-dev mailing list