<div dir="ltr">Hello devs,
<br>
<br>When running pygrass.utils.get_raster_for_points repeatedly, it appears
that the python memory allocation continuously increases until all ram
is consumed, even if the extracted values are not being collected (or
are overwriting the same variable).
<br>
<br>I noticed this when extracting raster data at point locations, when
using a large point dataset, even though I had pre-allocated a numpy
array to receive the results.
<br>
<br>Below is an example on the nc_spm_08_grass7 example data (in the landsat
mapset), repeating the operation say 50 times on the same point vector
dataset. I wouldn't have expected the memory consumption to continuously
increase for this operation, because I'm overwriting the 'arr' variable
each time. However, if you repeat this enough times, you will run out of
system memory and the allocated memory does not appear to be released,
i.e. even if you manually force garbage collection.
<br>
<br>Any suggestions?
<br>
<br>
<br>from grass.pygrass.vector import VectorTopo
<br>from grass.pygrass.raster import RasterRow
<br>from grass.pygrass.modules.shortcuts import raster as r
<br>from grass.pygrass.gis.region import Region
<br>from grass.pygrass.utils import get_raster_for_points
<br>
<br>reg = Region()
<br>reg.from_rast("landclass96")
<br>reg.write()
<br>reg.set_raster_region()
<br>
<br>r.random(input="landclass96", npoints=200000, vector="landclass96_roi",
<br> overwrite=True)
<br>
<br>points = VectorTopo("landclass96_roi")
<br>points.open("r")
<br>
<br># repeat spatial query of raster
<br>for i in range(50):
<br> with RasterRow("lsat5_1987_10") as src:
<br> arr = get_raster_for_points(points, src)
<br>
</div>