# Memory leak with BenchmarkTools?

**URL:** https://discourse.julialang.org/t/memory-leak-with-benchmarktools/31282
**Category:** General Usage
**Tags:** question
**Created:** [November 19, 2019, 7:04pm UTC](https://discourse.julialang.org/t/memory-leak-with-benchmarktools/31282 "2019-11-19T19:04:21Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)
#### Post date: [November 19, 2019, 7:04pm UTC](https://discourse.julialang.org/t/memory-leak-with-benchmarktools/31282/1 "2019-11-19T19:04:21Z")

</div>

I make numerous calls to `@belapsed` within a loop and I see the memory consumption constantly increasing…

Anybody experienced such problem ?`

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [November 19, 2019, 7:30pm UTC](https://discourse.julialang.org/t/memory-leak-with-benchmarktools/31282/2 "2019-11-19T19:30:22Z")

</div>

It will probably keep piling up until GC decides it is time for some GCing.

---

<div class="post-metadata">

### Author: ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)
#### Post date: [November 19, 2019, 8:18pm UTC](https://discourse.julialang.org/t/memory-leak-with-benchmarktools/31282/3 "2019-11-19T20:18:45Z")

</div>

Well, I am not sure. After a talk with @ffevotte, it could be caused by the creation of a lot of not-so-temporary functions created via calls like `t=@belapsed $f($operands...)` that I use inside my own bench function taking a function variable `f` for argument…

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [November 19, 2019, 8:27pm UTC](https://discourse.julialang.org/t/memory-leak-with-benchmarktools/31282/4 "2019-11-19T20:27:34Z")

</div>

Are you interpolating new variables in the loop? This will likely make new functions that refer to these variables and these will not be reclaimed

---

<div class="post-metadata">

### Author: ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)
#### Post date: [November 19, 2019, 8:48pm UTC](https://discourse.julialang.org/t/memory-leak-with-benchmarktools/31282/5 "2019-11-19T20:48:38Z")

</div>

Yes, there are new variables but with the same type… I do not really understand why it creates new functions (f exists).

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [November 19, 2019, 8:51pm UTC](https://discourse.julialang.org/t/memory-leak-with-benchmarktools/31282/6 "2019-11-19T20:51:28Z")

</div>

To make the function benchmarked look like a normal function with a local variable.

---

<div class="post-metadata">

### Author: ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)
#### Post date: [November 19, 2019, 8:56pm UTC](https://discourse.julialang.org/t/memory-leak-with-benchmarktools/31282/7 "2019-11-19T20:56:42Z")

</div>

OK, I think I understand your point. So I can’t really figure how to create a lot of benchmark curves with BenchmarkTools… Maybe I should launch new Julia processes within Julia (Distributed with add and rm procs ?)
