class_public
class_public copied to clipboard
Memory Tracking and Termination Garbage Collection for CLASS v3.2.0
Addresses Open Issues: #176 and possibly #528 Impacts Users: @hdp1213 @carlosggarcia @danielsf @mcosta18
Replaces all malloc()
, realloc()
, calloc()
, and free()
calls with reference-tracked versions. POSIX semantics are honoured. This allows all allocated memory to be freed at any time, regardless of CLASS state. _FAILURE_
conditions have been adjusted to release all allocated memory.
This repairs memory leaks that occur when CLASS is driven from the python wrapper, but fails to complete computations for various reasons, e.g. untabulated He fraction in the reionization code, choices of model parameters during MC that result in non-viable cosmologies/intergrator precision issues, etc.
Memory is tracked with a minimal doubly-linked list. Additions occur at the head for maximal performance on allocation and free. Cooperates with OpenMP as it is used within the v3.2.0 code.
(Note that this patch does not introduce tracked memory allocations within the python wrapper, and so will not fix leaks within the wrapper, if they exist.)