I am working with many GDAL rasters in memory in Python. Users on forums suggest using either one of two formats; 'VRT' or 'MEM'. I am confused about the difference between GDAL's 'MEM' format and GDAL's 'VRT' format however. I want to process many images with gdal.Warp, and make sure that I clear memory between each image to prevent leakage. Let's say I use warp and want to write the results to a location in memory as such:
vrtresult = gdal.Warp('/vsimem/swir.vrt', swir, options=upsample_options, format="VRT")
When I subsequently want to remove the swir.vrt from memory, I am supposed to use gdal.Unlink('/vsimem/swir.vrt'). Afterwards however vrtresult still contains the gdal object, which suggests to me that it is more than a handle referring to a location in-memory. If that is the case, does it store the result in memory twice? If I use the memory format however, for example as such;
memresult = gdal.Warp('/vsimem/swir.tif', swir, options=upsample_options, format="MEM")
I cannot even unlink. Using gdal.Unlink('/vsimem/swir.tif') will return "RuntimeError: unknown error occurred" (when you have gdal.UseExceptions() enabled). The 'MEM' format seems to be made just for the application I mention above, though there is no clear way of clearing memory. So I would like to know what the difference is between the two, and which would be cleanest to use if I want to temporarily do something in-memory.