# Memory leaking with threading

**URL:** <https://discourse.julialang.org/t/memory-leaking-with-threading/6677>\
**Category:** General Usage\
**Created:** [October 25, 2017, 12:55pm UTC](https://discourse.julialang.org/t/memory-leaking-with-threading/6677 "2017-10-25T12:55:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tomas\_Pevny](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomas_pevny/32/25466_2.png) [@Tomas\_Pevny](https://discourse.julialang.org/u/Tomas_Pevny)\
**Post date:** [October 25, 2017, 12:55pm UTC](https://discourse.julialang.org/t/memory-leaking-with-threading/6677/1 "2017-10-25T12:55:45Z")

</div>

Hi,

I adapted Flux.jl to calculate gradinets using multiple threads. The approach is relatively simple, as I divide the minibatch in approximately equal sizes and let each thread calculate the gradient on the minibatch and then I average the gradients on the end. Yet, I have a strong suspicion that there is some memory leaking.  
I do not know, how to at the moment reproduce the problem. Can anyone suggest, how to track down the source of the problem?  
Does anyone have similar problems?

Thanks for any help in advance.  
Tomas

---

<div class="post-metadata">

**Author:** ![MikeInnes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikeinnes/32/3656_2.png) [@MikeInnes](https://discourse.julialang.org/u/MikeInnes)\
**Post date:** [October 26, 2017, 8:33am UTC](https://discourse.julialang.org/t/memory-leaking-with-threading/6677/2 "2017-10-26T08:33:54Z")

</div>

So just to clarify, running the code without threading doesn’t leak, but just adding `@threads` causes a leak?

I don’t know a huge amount about the threading infrastructure, so I can only really suggest cutting down the program as much as possible and reporting it to base.
