esmf-org / esmf

The Earth System Modeling Framework (ESMF) is a suite of software tools for developing high-performance, multi-component Earth science modeling applications.
https://earthsystemmodeling.org/
Other
156 stars 75 forks source link

ESMF_RUNTIME_ environment variable to affect garbage collection behavior #277

Open theurich opened 2 months ago

theurich commented 2 months ago

Currently some of the garbage collection code that runs during ESMF_Finalize() or ESMC_Finalize() is commented out. An idea that came out of the discussion #269 is to introduce a run-time environment variable ESMF_RUNTIME_GARBAGE_EMPTY, which if set would activate the currently commented out parts of the garbage collection code. This would allow running codes with full garbage collection enable to:

Discussed in https://github.com/orgs/esmf-org/discussions/269

Originally posted by **AbhiHampiholi** July 25, 2024 ### Requirements - [X] Reviewed [ESMF Reference Manual](https://earthsystemmodeling.org/doc/) - [X] Searched [GitHub Discussions](https://github.com/orgs/esmf-org/discussions?discussions_q=) ### Affiliation(s) AirMettle, Inc ### ESMF Version 8.6.0 ### Issue Hello, In my code, all the allocated ESMC objects are reported as memory leaks despite calling the ESMC destroy functions and the Finalize function at the end. I noticed that the call to `ESMC_GridDestroy` calls the `ESMCI::Grid::destroy(&gridp)` which has signature ` static int destroy(Grid **grid, bool noGarbage=false);` since no second argument is passed, the noGarbage flag is always false by default and inside the destroy function the `delete` is always skipped ``` // optionally delete the complete object and remove from garbage collection if (noGarbage){ VM::rmObject(*gridArg); // remove object from garbage collection delete (*gridArg); // completely delete the object, free heap } ``` I've attached a reproducible example here (copied from the example @danrosen25 sent me yesterday) [test_memleak.tar.gz](https://github.com/user-attachments/files/16380588/test_memleak.tar.gz) `valgrind --leak-check=full ./exeMemLeak` reveals the memory leaks. Let me know if I am missing something or if this is not-reproducible. If there isn't anything wrong with my setup, the fix might be to provide a way to set `noGarbage=true` while calling `ESMCI::Grid::destroy()` but I am not sure.