Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak when using MemoryFile #1953

Closed
valpesendorfer opened this issue Jun 22, 2020 · 1 comment
Closed

Memory leak when using MemoryFile #1953

valpesendorfer opened this issue Jun 22, 2020 · 1 comment
Assignees
Labels
Milestone

Comments

@valpesendorfer
Copy link

valpesendorfer commented Jun 22, 2020

Memory used with MemoryFile doesn't seem to be released after the reference is gone. When creating MemoryFiles iteratively, the memory consumption continues to increase with every iteration.

Seems to be an issue with version 1.1.5 - works as expected with version 1.1.4.

Expected behavior and actual behavior.

Expected:

Memory to be released after reference is gone, no memory increase in iteration.

Actual:

Memory is not released, consumed memory increases with every iteration.

Comparison between 1.1.4 and 1.1.5:

image

Steps to reproduce the problem.

import psutil

import numpy as np
import rasterio

def main():

    profile = dict(
        count=1,
        height=2000,
        width=7200,
        nodata=-9999,
        dtype='int16')

    for it in range(100):

        arr = np.random.randint(0, 100, size=(2000,7200), dtype='int16')

        with rasterio.MemoryFile() as memf:
            with memf.open(driver='GTiff', **profile) as dataset:
                dataset.write(arr, 1)

        del memf
    
        mem_pct = psutil.virtual_memory().percent
        print(f'Memory used: {mem_pct}%')


if __name__ == '__main__':
    main()

Operating system

NAME="Ubuntu"
VERSION="18.04.4 LTS (Bionic Beaver)"

Rasterio version and provenance

pip freeze

affine==2.3.0
attrs==19.3.0
click==7.1.2
click-plugins==1.1.1
cligj==0.5.0
numpy==1.19.0
psutil==5.7.0
pyparsing==2.4.7
rasterio==1.1.5
snuggs==1.4.7

rio wheel from pypi:

rasterio-1.1.5-cp37-cp37m-manylinux1_x86_64.whl

pip:

pip 19.2.3

python:

Python 3.7.7

@sgillies sgillies self-assigned this Jun 22, 2020
@sgillies sgillies added this to the 1.1.6 milestone Jun 22, 2020
@sgillies
Copy link
Member

Thanks for the report @valpesendorfer . We did change the implementation in 1.1.5. I'll look into it soon.

@sgillies sgillies added the bug label Jun 22, 2020
Kirill888 added a commit to opendatacube/geobase that referenced this issue Jul 3, 2020
Also re-order and split compilation steps.

- GDAL
- netcdf
- fiona
- shapely
- proj
- rasterio

Items lower in the list change most

see: rasterio/rasterio#1953
Kirill888 added a commit to opendatacube/geobase that referenced this issue Jul 3, 2020
Also re-order and split compilation steps.

- GDAL
- netcdf
- fiona
- shapely
- proj
- rasterio

Items lower in the list change most

see: rasterio/rasterio#1953
omad added a commit to GeoscienceAustralia/dea-orchestration that referenced this issue Jul 13, 2020
yellowcap added a commit to tesselo/tesselo that referenced this issue Jul 16, 2020
omad added a commit to GeoscienceAustralia/dea-orchestration that referenced this issue May 20, 2021
@willemmirkovich willemmirkovich mentioned this issue Jan 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants