large_image icon indicating copy to clipboard operation
large_image copied to clipboard

is there a memory leak in large_image.open? how to relase the memory after image closed

Open zhusihan-python opened this issue 2 years ago • 3 comments

hello, i use large_image to open a till as a tile server with PyQt, yet i found that large_image.open will occupy memory much more than the image data itself, and won't return the memory after the image was closed until the python process was killed like in the source.getThumbnail, the memory usage increased by 400mb while the thumbnail image is only 130kb e5ab0319d454b6bd057c420c155313a at first i thought its the source.cache that eats the memory, so i clear the source.cache, and find that it only use 15mb

before clear cache size 15442063
before clear dataset size 200
after clear cache size 5836
after clear dataset size 200
after clear cache LRUCache({}, maxsize=2039, currsize=0)
after clear dataset <osgeo.gdal.Dataset; proxy of <Swig Object of type 'GDALDatasetShadow *' at 0x000001CE04119570> >

the memory usage surge in this line 5aca4c3b634f95b9ef875d01a9f904c yet the _imgToNumpy itself didn't use that much memory, i can't figure out what happended in tilesource/utilities, i doubt that maybe there is memory leakage in some other places, as the memory usage just keep growing, is there a way to close the opened image by large_image properly and return the memory back

my environment: windows 10 python 3.9 large_image 1.14.2

zhusihan-python avatar May 25 '22 13:05 zhusihan-python

There are two main caches: the source cache and the tile cache. The tile cache can store data in either the python process or in memcached based on configuration. If you use large_image.cache_util.cachesClear(), does that free memory?

Based on your output, you are using the gdal tile source. gdal might be reading a large amount of your file to get enough information to get the data for the requested thumbnail or region.

The memory usage may also be when the gdal libraries are loaded into memory (they aren't small) -- so it may be that they stay in memory until the process is terminated (in which case the actually memory use is the .so/.dll associated with gdal).

manthey avatar May 25 '22 13:05 manthey

large_image.cache_util.cachesClear() didn't work, i guess its the second reason as i open multi tiff images, the memory is growing. the gdal libraries are loaded only once i think.

zhusihan-python avatar May 26 '22 01:05 zhusihan-python

@zhusihan-python Are you still having issues with memory? If so, can you try with the latest version from pypi (or from master) and see if that has any improvement?

manthey avatar Aug 16 '22 13:08 manthey

Closing this. Please reopen if you think it is still an issue.

manthey avatar Jun 30 '23 16:06 manthey