# Can RuntimeGeneratedFunctions.jl cause memory leak issue?

**URL:** <https://discourse.julialang.org/t/can-runtimegeneratedfunctions-jl-cause-memory-leak-issue/112261>\
**Category:** Modelling & Simulations\
**Tags:** runtimegeneratedfunc\
**Created:** [March 28, 2024, 11:54pm UTC](https://discourse.julialang.org/t/can-runtimegeneratedfunctions-jl-cause-memory-leak-issue/112261 "2024-03-28T23:54:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![VPBML](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vpbml/32/212617_2.png) [@VPBML](https://discourse.julialang.org/u/VPBML)\
**Post date:** [March 28, 2024, 11:54pm UTC](https://discourse.julialang.org/t/can-runtimegeneratedfunctions-jl-cause-memory-leak-issue/112261/1 "2024-03-28T23:54:30Z")

</div>

Hi,

I am writing a Genetic Programming-styled code to search for solutions to specific problems. The solutions are in the form of functions. Thus, I use RuntimeGeneratedFunctions.jl to generate functions in runtime in order to evaluate their fitnesses. As the code runs (on WSL) and time goes by, the amount of available RAM on my computer becomes less and less until the system forcibly closes the terminal. I suspect it is due to the generated functions. I wonder if it is a known problem and if there exists a solution. Thank you.

Here is the part of the code that involves RuntimeGeneratedFunctions.jl:

```julia
function eval_solution(expr, data, eval_genfunc) 
      f = expr
      f1 = @RuntimeGeneratedFunction(f)
      fitness = evaluate_genfunc(f1, data)
      return fitness
 end

```

Here, **expr** is the Expr containing the content of the function to be generated, **data** is the data necessary to calculate the fitness of the generated function, **eval\_genfunc** is a custom function to calculate the fitness of a generated function. eval\_genfunc looks like this:

```julia
function eval_genfunc(f1, data) 
      parameters = f1(data)
      score = g(parameters) % g performs a simulation with given parameters and extracts some information from there as the score
      return score
end

```

The function eval\_solution( ) is used in multithreading mode in a main function:

```julia
function main(...)
 ...
 while iterate > 0
   Threads.@threads for i in n_threads
      expr = ... % Calling the function to generate an expr
      fitness = eval_solution(expr, data, eval_genfunc)
      ...
   end
   ...
   iterate -= 1
 end
 ...
end

```

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [March 31, 2024, 4:33pm UTC](https://discourse.julialang.org/t/can-runtimegeneratedfunctions-jl-cause-memory-leak-issue/112261/2 "2024-03-31T16:33:34Z")

</div>

Duplicate of [Can RuntimeGeneratedFunctions.jl cause memory leak issue? · Issue #87 · SciML/RuntimeGeneratedFunctions.jl · GitHub](https://github.com/SciML/RuntimeGeneratedFunctions.jl/issues/87)
