# GC problem

**URL:** <https://discourse.julialang.org/t/gc-problem/83391>\
**Category:** New to Julia\
**Created:** [June 27, 2022, 9:49am UTC](https://discourse.julialang.org/t/gc-problem/83391 "2022-06-27T09:49:20Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brian1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brian1/32/49250_2.png) [@Brian1](https://discourse.julialang.org/u/Brian1)\
**Post date:** [June 27, 2022, 9:49am UTC](https://discourse.julialang.org/t/gc-problem/83391/1 "2022-06-27T09:49:20Z")

</div>

First I run this kind of code:

```julia
GC.enable(false)

Do something heavy work, which allocate 64GB or more memory allocation

GC.enable(true)

```

Then, I go to relase the memory:

```julia
GC.gc(true)

```

But it the program keeps runing, never stop. What is going on?

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [June 27, 2022, 9:55am UTC](https://discourse.julialang.org/t/gc-problem/83391/2 "2022-06-27T09:55:46Z")

</div>

> [@Brian1](#):
>
> But it the program keeps runing, never stop. What is going on?

What do you mean by that? Do you mean your program doesn’t stop execution?

It’s hard to help without knowing what code you’re running or what exactly the problem is.

---

<div class="post-metadata">

**Author:** ![Brian1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brian1/32/49250_2.png) [@Brian1](https://discourse.julialang.org/u/Brian1)\
**Post date:** [June 27, 2022, 9:59am UTC](https://discourse.julialang.org/t/gc-problem/83391/3 "2022-06-27T09:59:20Z")

</div>

Yes, the program does not stop execution, it seems will be running forever, as you can see:

![image](https://global.discourse-cdn.com/julialang/original/3X/6/4/642bf6f042b3c061b12b8fd4f585ba33fdde4644.png)

And the memory does not a reaction to the `GC.gc()`:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/0/b/0bde25e11572183ae81733ab580b567f243f933c.png)

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [June 27, 2022, 10:22am UTC](https://discourse.julialang.org/t/gc-problem/83391/4 "2022-06-27T10:22:23Z")

</div>

> [@Brian1](#):
>
> Yes, the program does not stop execution, it seems will be running forever, as you can see:

You are in a notebook (jupyter?), why should the kernel stop?

I’m not sure about the code surrounding this, but the original `distral` object is still there, so why should it be gone?

---

<div class="post-metadata">

**Author:** ![Brian1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brian1/32/49250_2.png) [@Brian1](https://discourse.julialang.org/u/Brian1)\
**Post date:** [June 27, 2022, 10:26am UTC](https://discourse.julialang.org/t/gc-problem/83391/5 "2022-06-27T10:26:06Z")

</div>

Yes, I am in a notebook (Vscode). The kernel should not to stop (as it happening), but the excution cell (Number [7], `GC.gc()`) should stop, but it not.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [June 27, 2022, 11:05am UTC](https://discourse.julialang.org/t/gc-problem/83391/6 "2022-06-27T11:05:48Z")

</div>

Are you certain it doesn’t stop? `GC.gc()` only returns `nothing` after all. Your CPU usage also suggests that nothing is running, with only 6% being in use.

---

<div class="post-metadata">

**Author:** ![Brian1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brian1/32/49250_2.png) [@Brian1](https://discourse.julialang.org/u/Brian1)\
**Post date:** [June 27, 2022, 12:43pm UTC](https://discourse.julialang.org/t/gc-problem/83391/7 "2022-06-27T12:43:14Z")

</div>

Yes, definit sure. I tried several times, and end of getting the same situation.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [June 27, 2022, 12:46pm UTC](https://discourse.julialang.org/t/gc-problem/83391/8 "2022-06-27T12:46:46Z")

</div>

Do you have an example I could use to reproduce this on my end? I’m still not sure I understand exactly what you’re doing in the notebook.

---

<div class="post-metadata">

**Author:** ![albheim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albheim/32/34660_2.png) [@albheim](https://discourse.julialang.org/u/albheim)\
**Post date:** [June 27, 2022, 12:59pm UTC](https://discourse.julialang.org/t/gc-problem/83391/9 "2022-06-27T12:59:41Z")

</div>

So are you saying that the cell is still running and blocking other execution? So if you for example try to run `1+1` in another cell after that, it would lock up an never run?

Or are you saying the cell finishes, but the `gc` call does not do what you expect?

---

<div class="post-metadata">

**Author:** ![Brian1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brian1/32/49250_2.png) [@Brian1](https://discourse.julialang.org/u/Brian1)\
**Post date:** [June 27, 2022, 2:00pm UTC](https://discourse.julialang.org/t/gc-problem/83391/10 "2022-06-27T14:00:40Z")

</div>

> [@albheim](#):
>
> the cell is still running and blocking other execution

That is the situation.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [June 27, 2022, 2:01pm UTC](https://discourse.julialang.org/t/gc-problem/83391/11 "2022-06-27T14:01:56Z")

</div>

I wonder if you are creating an infinite loop of finalizers somehow.

---

<div class="post-metadata">

**Author:** ![Brian1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brian1/32/49250_2.png) [@Brian1](https://discourse.julialang.org/u/Brian1)\
**Post date:** [June 27, 2022, 2:04pm UTC](https://discourse.julialang.org/t/gc-problem/83391/12 "2022-06-27T14:04:12Z")

</div>

Proberbly not, when I just run `distrall[1:14](pnl_func)`, everything is ok.

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [June 27, 2022, 2:30pm UTC](https://discourse.julialang.org/t/gc-problem/83391/13 "2022-06-27T14:30:55Z")

</div>

> [@Brian1](#):
>
> ```julia
> GC.enable(false)
> 
> Do something heavy work, which allocate 64GB or more memory allocation
> 
> ```

I suggest don’t do that. While `GC.enable(false)` is an option to use, it is (or can be, very) dangerous (I would rarely if ever use it, and then very carefully), especially with 64 GB allocated. I find it likely you ran out of memory (not sure what happens for you, on Linux it might kill some other process, on Windows it’s I think guaranteed not to happen).

Note, there’s this new option in Julia 1.9:

```julia
--heap-size-hint=<size> Forces garbage collection if memory usage is higher than that value.

```

Ideally you shouldn’t have to mess with some non-default option, and I’m not sure, they may have changed the default for that option. Only for some unusual situations, such as performance tuning or real-time, you should need non-default.
