class_public icon indicating copy to clipboard operation
class_public copied to clipboard

Memory tracking and garbage collection to CLASS v3.2.0

Open kcroker opened this issue 7 months ago • 0 comments

Addresses Open Issues: https://github.com/lesgourg/class_public/issues/176 and possibly https://github.com/lesgourg/class_public/issues/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.)

kcroker avatar Jul 18 '24 22:07 kcroker