Skip to content

Possible memory leak when reading data #11

Description

@elisalle

When repeatedly reading the same data from a netCDF via mdal-python, the memory usage on the computer rises until it is full, at which point the computer crashes. The netCDF I was reading is here: https://nelenschuurmans-my.sharepoint.com/:u:/g/personal/eli_salle_nelen-schuurmans_nl/EQF4yujI03hNi_9gFPd8L7gBDWmAseLXkCBrKSWy5gK9dg?e=ouudP9
My code is as follows:

from mdal import Datasource
from pathlib import Path
import gc

mypath = "results_3di.nc"
ds = Datasource(mypath)

with ds.load() as mesh:
    print("mesh loaded")
    group = mesh.group(3)
    for i in range(30):
        for i in range(0, group.dataset_count):
            data = group.data(i)
            # make very sure the variable gets taken out of memory:
            del(data)
            gc.collect()

I also tried exiting the context manager on each loop to see if that would help, but it made no difference:

from mdal import Datasource
from pathlib import Path
import gc

mypath = "results_3di.nc"
ds = Datasource(mypath)

for i in range(30):
    with ds.load() as mesh:
        print("mesh loaded")
        group = mesh.group(3)
        for i in range(0, group.dataset_count):
            data = group.data(i)
            # make very sure the variable gets taken out of memory:
            del(data)
            gc.collect()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions