-
Notifications
You must be signed in to change notification settings - Fork 108
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
why so many memory leaks in chgres_cube? #729
Comments
I decided to take a look at this again today while looking through the Issues. All of the memory leaks I'm seeing in the current version of chgres_cube appear to be associated with either g2 or ESMF routines. None of the memory leaks show an address location in any of the chgres_cube files any more so I'm not sure they're something that we can fix. I do, however, see some memory leaks originating from an fvcom_tools test, ftst_readfvcomnetcdf.F90 . So that might need to be addressed, but I'm not sure if this Issue is the place to do that. Does anyone else see any chgres_cube tests that have memory leaks that trace back to actual test code and not just external library routines? If not, should we go ahead and close this? |
Just because the memory is in another library does not mean that UFS_UTILS is not responsible. I can't speak for ESMF, but for the latest release of g2, there are no memory leaks (if g2_finalize() is called at the end of all processing). For many libraries, including g2, a user causes memory to be allocated, and then must call other library functions to free the memory. Now I can't actually speak for ESMF. But if they have done things correctly, all resources of theirs that were opened, should be closable. |
So how would one go about actually tracing back to where the memory leaks occurred in chgres_cube code if the address sanitizer output doesn't even list a file in the chgres_cube repository? For example: |
I ran one test (ftst_read_atm_grib2) through valgrind and pretty much every instance of ESMF_FieldCreate, ESMF_GridCreate, and getgb2 are being flagged for possible or definite memory leaks. I double and triple checked that all Fields and Grids whose creation calls are being flagged were in fact also attached to destroy commands at the end of the test file. I'm not at all sure what to think of every single getgb2 call being flagged. As an example: |
The g2 library allocates unreachable memory in the getgb2() and related subroutines. THe only way to free this memory is to call the new subroutine g2_finalize() after all g2 operations are complete. This will free the g2 memory. Documentation here: https://noaa-emc.github.io/NCEPLIBS-g2/getidx_8F90.html#ac02dafd6109baa69a66dc278d6b0c083 So this is a great example of how memory checking can find real bugs and allow us to fix them. This was found (and the gf_finalize() added) in response to such a memory checking effort from a using application. As for ESMF, I suggest you contact their team and ask. Probably there is some function that needs to be called to free memory, either a finalize function or some function to close open ESMF objects. |
UFS_UTILS currently uses g2 v3.4.5 which does not have that command, so it won't be possible to remove those leaks associated with g2 unless we update libraries. I'll see what the ESMF folks have to say. |
Are these a known issue? Why so many memory leaks?
The text was updated successfully, but these errors were encountered: