html_url,issue_url,id,node_id,user,created_at,updated_at,author_association,body,reactions,performed_via_github_app,issue https://github.com/pydata/xarray/issues/7404#issuecomment-1366880017,https://api.github.com/repos/pydata/xarray/issues/7404,1366880017,IC_kwDOAMm_X85ReO8R,1217238,2022-12-28T19:46:07Z,2022-12-28T19:46:07Z,MEMBER,"If you care about memory usage, you should explicitly close files after you use them, e.g., by calling `ds.close()` or by using a context manager. Does that work for you?","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1512460818 https://github.com/pydata/xarray/issues/7404#issuecomment-1366545996,https://api.github.com/repos/pydata/xarray/issues/7404,1366545996,IC_kwDOAMm_X85Rc9ZM,14808389,2022-12-28T10:28:22Z,2022-12-28T10:28:22Z,MEMBER,"I'm not sure how `memory_profiler` calculates the memory usage, but I suspect that this happens because python's garbage collector does not have to run immediately after the `del`. Can you try manually triggering the garbage collector? ```python import gc import os import psutil import xarray as xr from memory_profiler import profile @profile def main(): path = 'ECMWF_ERA-40_subset.nc' gc.collect() print(f""Before opening file: {psutil.Process(os.getpid()).memory_info().rss / 1024 ** 2} MiB"") ds = xr.open_dataset(path) del ds gc.collect() print(f""After opening file: {psutil.Process(os.getpid()).memory_info().rss / 1024 ** 2} MiB"") if __name__ == '__main__': print(f""Start: {psutil.Process(os.getpid()).memory_info().rss / 1024 ** 2} MiB"") main() print(f""End: {psutil.Process(os.getpid()).memory_info().rss / 1024 ** 2} MiB"") ```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1512460818