Skip to content
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

Overhaul memory deallocation #322

Closed
chaukap opened this issue Jun 12, 2019 · 1 comment
Closed

Overhaul memory deallocation #322

chaukap opened this issue Jun 12, 2019 · 1 comment
Assignees
Milestone

Comments

@chaukap
Copy link
Contributor

chaukap commented Jun 12, 2019

Right now deallocation of gridCells has not been touched in ST_grid.c. We need to make sure everything we allocated is freed up.

@chaukap chaukap added this to the gridded_code milestone Jun 12, 2019
@chaukap chaukap self-assigned this Jun 12, 2019
chaukap referenced this issue Jun 12, 2019
I removed all referenced to depreciated structs and arrays, then freed up most of the momory. I still need to free SXW, RGroup, Species and the accumulators, so do not attempt to run this branch on a supercomputer yet.
chaukap pushed a commit that referenced this issue Jun 17, 2019
deallocate_Globals now handles all global pointers. I added RGroup and Species deallocation to complete the function. (issue #322)
chaukap referenced this issue Jun 17, 2019
This commit overhauls deallocation in both gridded and non-gridded modes.
In ST_main.c
* Added a boolean parameter to deallocate_Globals.
* Wrapped some of the variables in an if statement dependent on the parameter. I did this because in gridded mode these pointers do not allocate any memory, but in non-gridded mode they do.

In sxw.c:
* Removed free_sxw_memory, _deallocate_memory, and load_sxw_memory
* I removed free_sxw_memory because it overcomplicated the code. It's only call was in free_all_sxw_memory, so I combined them to make the code more readable.
* I removed load_sxw_memory because it is depreciated, and referenced free_sxw_memory which I had already deleted.
* I removed _deallocate_memory because it was redundant and unused.
* In free_all_sxw_memory I went through each struct and deallocated every pointer to ensure no memory is leaked.
* I did NOT delete SXW->f_files because it is never actually allocated memory. The previous call to Mem_Free(SXW->f_files.in) worked because it pointed to another variable which is allocated, but calling the function multiple times in gridded mode revealed that it is unnecessary.

In ST_grid.c:
* Added a few additional pointers to _free_grid_memory.
* Added a loop which loads in a cell, then calls the non-gridded mode deallocation function. This reduces code reuse.
chaukap pushed a commit that referenced this issue Jun 17, 2019
These calls were causing the branch to break. (#322)
chaukap pushed a commit that referenced this issue Jun 21, 2019
chaukap pushed a commit that referenced this issue Jul 24, 2019
There were two sources of memory leaks that I found using valgrind.
* All arrays from SXWResources were not completely freed.
* The accumulators were never freed. 

I took take of both of these sources.
@chaukap
Copy link
Contributor Author

chaukap commented Jul 28, 2019

I used Valgrind one more time, and I couldn't find any memory leaks on the STEPWAT2 side. I will therefore close this issue.

@chaukap chaukap closed this as completed Jul 28, 2019
dschlaep added a commit that referenced this issue Dec 22, 2022
- SOILWAT2 has now multiple soil water release curves (SWRC) implemented
- updated SOILWAT2 submodule on branch release/devel_v7.0.0 to commit a6c367aef07b746a43b459067ee0ef0139f9f60b "Merge pull request #322 from DrylandEcology/feature_swrc"

-> new SOILWAT2 inputs include: swrc_name (to select a SWRC), ptf_name (to select a pedotransfer function if used), has_swrcp (logical to determine if SWRC parameters are used from new input file or calculated at run-time with selected PTF), and swrc_params (per soil layer parameters of the selected SWRC if used)
-> default values (swrc_name = Campbell1974, ptf_name = Cosby1984AndOthers, has_swrcp = FALSE) re-created previous behavior (except for a small fix for when soil moisture values occur above field capacity and below saturation levels)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant