Skip to content

Memory leak on index access #237

@EmptySpace99

Description

@EmptySpace99

The memory allocated when an index is opened is not correctly released, in fact when the index is opened and closed multiple times you can notice the memory increase. Does anyone have any idea how to solve this?

How to reproduce

Create and store my index

grib_path = "..."
index_path = "..."
index = pygrib.index(grib_path, 'shortName')
index.write(index_path)
index.close()

Access to the index

index = pygrib.index(index_path)
index.select(shortName='u') # Allocates memory
index.close() # Closed index but memory is not released (easily checkable using a memory profiler)

Memory profiler

Line #    Mem usage    Increment  Occurrences   Line Contents
=============================================================
233    231.4 MiB    231.4 MiB           1       @profile   
234                                             def test(self, index_path: str, short_name: str):
235    232.0 MiB      0.6 MiB           1           index = pygrib.index(index_path)
236    356.9 MiB    124.9 MiB           1           index.select(shortName=short_name)
237    356.9 MiB      0.0 MiB           1           index.close()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions