# \#garbage-collection

**URL:** https://discourse.julialang.org/tag/garbage-collection/358.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Region-based GC for Julia: worst event pause 4 ms → 55 µs](https://discourse.julialang.org/t/region-based-gc-for-julia-worst-event-pause-4-ms-55-s/139158)

<div class="topic-metadata">

**Author:** [@melevy](https://discourse.julialang.org/u/melevy)\
**Replies:** 8\
**Last updated:** [September 8, 2026, 5:58pm UTC](https://discourse.julialang.org/t/region-based-gc-for-julia-worst-event-pause-4-ms-55-s/139158 "2026-09-08T17:58:13Z")

</div>

I run discrete-event simulations that drive hardware in the loop, which means every event has a deadline of about 100 µs. Julia’s collector is fine on throughput but occasionally it stops the world for milliseconds, an…

---

## [GC problems with \`jl\_gc\_unsafe\_enter\` with multithreaded embedding](https://discourse.julialang.org/t/gc-problems-with-jl-gc-unsafe-enter-with-multithreaded-embedding/104467)

<div class="topic-metadata">

**Author:** [@Keluaa](https://discourse.julialang.org/u/Keluaa)\
**Replies:** 3\
**Last updated:** [January 30, 2026, 7:39am UTC](https://discourse.julialang.org/t/gc-problems-with-jl-gc-unsafe-enter-with-multithreaded-embedding/104467 "2026-01-30T07:39:26Z")

</div>

I am currently developping a Kotlin library to embed Julia in the JVM, with the goal to support multithreading with jl\_adopt\_thread(). The main issue is that when using some frameworks, there may not be a way to be in co…

---

## [Best practice for calling Julia functions via API](https://discourse.julialang.org/t/best-practice-for-calling-julia-functions-via-api/135086)

<div class="topic-metadata">

**Author:** [@Chrysoberyl](https://discourse.julialang.org/u/Chrysoberyl)\
**Replies:** 0\
**Last updated:** [January 15, 2026, 8:04pm UTC](https://discourse.julialang.org/t/best-practice-for-calling-julia-functions-via-api/135086 "2026-01-15T20:04:30Z")

</div>

In my setup, a Julia function calls a C/Rust function play(agent, environment), which spawns some threads, and call functions on agent. agent and environment are Julia objects. Each of these foreign threads gets registe…

---

## [How does JuliaCall (PythonCall) protect Julia objects in Python code from Julia's GC?](https://discourse.julialang.org/t/how-does-juliacall-pythoncall-protect-julia-objects-in-python-code-from-julias-gc/132836)

<div class="topic-metadata">

**Author:** [@Benny](https://discourse.julialang.org/u/Benny)\
**Replies:** 4\
**Last updated:** [October 4, 2025, 11:16am UTC](https://discourse.julialang.org/t/how-does-juliacall-pythoncall-protect-julia-objects-in-python-code-from-julias-gc/132836 "2025-10-04T11:16:43Z")

</div>

No practical purpose, just curious. For PythonCall in Julia code, it’s easy to imagine that a Julia wrapper increments an underlying CPython object’s reference count to protect it from CPython’s GC (I don’t know if this …

---

## [Question about GC.@preserve](https://discourse.julialang.org/t/question-about-gc-preserve/131999)

<div class="topic-metadata">

**Author:** [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Replies:** 1\
**Last updated:** [September 1, 2025, 9:31am UTC](https://discourse.julialang.org/t/question-about-gc-preserve/131999 "2025-09-01T09:31:30Z")

</div>

Consider the following two patterns: v = Vector(...) GC.@preserve v begin # unsafe stuff using pointer(v) end and v = Vector(...) # unsafe stuff using pointer(v) GC.@preserve v Are there situations where the sec…

---

## [Intermittent Segfault](https://discourse.julialang.org/t/intermittent-segfault/131694)

<div class="topic-metadata">

**Author:** [@TI36XPro](https://discourse.julialang.org/u/TI36XPro)\
**Replies:** 2\
**Last updated:** [August 21, 2025, 12:57am UTC](https://discourse.julialang.org/t/intermittent-segfault/131694 "2025-08-21T00:57:42Z")

</div>

Hello, I have recently started experiencing an intermittent segfault when using Julia with the vscode extension. I’ve been developing with this setup for well over a year and never experienced this before. I don’t even …

---

## [Strange GC issue on Julia 1.12-rc1](https://discourse.julialang.org/t/strange-gc-issue-on-julia-1-12-rc1/131529)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 9\
**Last updated:** [August 12, 2025, 9:07pm UTC](https://discourse.julialang.org/t/strange-gc-issue-on-julia-1-12-rc1/131529 "2025-08-12T21:07:17Z")

</div>

I am happy that I can now use multi-threading on Julia 1.12rc1. I had to do some changes to my code, but now it works. But the garbage collector behaves differently. I am using two different settings. First settings: j…

---

## [GC error / sefgault in a simple C wrapper](https://discourse.julialang.org/t/gc-error-sefgault-in-a-simple-c-wrapper/127032)

<div class="topic-metadata">

**Author:** [@Krastanov](https://discourse.julialang.org/u/Krastanov)\
**Replies:** 5\
**Last updated:** [March 17, 2025, 1:27pm UTC](https://discourse.julialang.org/t/gc-error-sefgault-in-a-simple-c-wrapper/127032 "2025-03-17T13:27:39Z")

</div>

I am attempting to make a julia wrapper for a C library. The C library is already available as a jll. I was attempting to use Clang.jl to make the wrapper, but whatever I am doing seems to be causing segfaults on garbage…

---

## [Can I manage the memory by myself?](https://discourse.julialang.org/t/can-i-manage-the-memory-by-myself/97250)

<div class="topic-metadata">

**Author:** [@zhijie\_sun](https://discourse.julialang.org/u/zhijie_sun)\
**Replies:** 16\
**Last updated:** [February 1, 2025, 7:03pm UTC](https://discourse.julialang.org/t/can-i-manage-the-memory-by-myself/97250 "2025-02-01T19:03:19Z")

</div>

I have a code, the GC live and RSS memory increased quickly when running, while I don’t need such big memory to do basic computation. I need to allocate lots of small dict for intermidiate computing before, and the memor…

---

## [Weird behaviour of GC with multithreaded array-access](https://discourse.julialang.org/t/weird-behaviour-of-gc-with-multithreaded-array-access/125433)

<div class="topic-metadata">

**Author:** [@wilhelm](https://discourse.julialang.org/u/wilhelm)\
**Replies:** 2\
**Last updated:** [January 31, 2025, 6:57pm UTC](https://discourse.julialang.org/t/weird-behaviour-of-gc-with-multithreaded-array-access/125433 "2025-01-31T18:57:31Z")

</div>

Hi! I recently worked with some big arrays and used multithreading to access and fill these arrays, but after the calculation it seemed like the GC did not manage to clear the ram used by the “non-main” thread. MWE: f…

---

## [Should Dict avoid GC allocations for isbits key/value types?](https://discourse.julialang.org/t/should-dict-avoid-gc-allocations-for-isbits-key-value-types/123613)

<div class="topic-metadata">

**Author:** [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Replies:** 3\
**Last updated:** [December 10, 2024, 1:16am UTC](https://discourse.julialang.org/t/should-dict-avoid-gc-allocations-for-isbits-key-value-types/123613 "2024-12-10T01:16:36Z")

</div>

Resizing arrays, when elements have primitive types or more generally isbits types, does not trigger any GC, as this is handled by the C runtime. Dictionaries are also allocation-free during most operations, except durin…

---

## [How to use ccall, cconvert, and unsafe\_convert in a convenient and memory-safe way?](https://discourse.julialang.org/t/how-to-use-ccall-cconvert-and-unsafe-convert-in-a-convenient-and-memory-safe-way/41932)

<div class="topic-metadata">

**Author:** [@sloede](https://discourse.julialang.org/u/sloede)\
**Replies:** 18\
**Last updated:** [June 24, 2020, 11:50am UTC](https://discourse.julialang.org/t/how-to-use-ccall-cconvert-and-unsafe-convert-in-a-convenient-and-memory-safe-way/41932 "2020-06-24T11:50:08Z")

</div>

I am writing Julia code to conveniently interface a C library, which in turn is just an interface to a C++ library. Therefore, many times I have to store pointers to void as the C interface does not know anything about t…

---

## [Acquiring locks in finalizers](https://discourse.julialang.org/t/acquiring-locks-in-finalizers/119628)

<div class="topic-metadata">

**Author:** [@remysucre](https://discourse.julialang.org/u/remysucre)\
**Replies:** 3\
**Last updated:** [September 20, 2024, 5:05pm UTC](https://discourse.julialang.org/t/acquiring-locks-in-finalizers/119628 "2024-09-20T17:05:56Z")

</div>

The manual has an example with a finalizer that acquires a lock (without blocking). However, in the Locks section it also says: The following are definitely leaf locks (level 1), and must not try to acquire any other l…

---

## [C struct garbage collection not run frequently enough](https://discourse.julialang.org/t/c-struct-garbage-collection-not-run-frequently-enough/116919)

<div class="topic-metadata">

**Author:** [@mattsignorelli](https://discourse.julialang.org/u/mattsignorelli)\
**Replies:** 28\
**Last updated:** [July 14, 2024, 11:42pm UTC](https://discourse.julialang.org/t/c-struct-garbage-collection-not-run-frequently-enough/116919 "2024-07-14T23:42:04Z")

</div>

I have a Julia interface to a C library where each C struct represents a number. In Julia, the mutable struct just contains a Ptr to the C struct, and the finalizer calls the C destructor. These C structs can be very me…

---

## [Is it possible to detect garbage collection on a custom struct?](https://discourse.julialang.org/t/is-it-possible-to-detect-garbage-collection-on-a-custom-struct/108338)

<div class="topic-metadata">

**Author:** [@ThummeTo](https://discourse.julialang.org/u/ThummeTo)\
**Replies:** 2\
**Last updated:** [January 4, 2024, 1:02pm UTC](https://discourse.julialang.org/t/is-it-possible-to-detect-garbage-collection-on-a-custom-struct/108338 "2024-01-04T13:02:48Z")

</div>

Hi! I am using an external library (LIB or DLL) to allocate and free memory that is not in the scope of the garbage collector, in the following example externalAlloc and externalFree. For better handling, I packed the m…

---

## [Question About New GC Threads](https://discourse.julialang.org/t/question-about-new-gc-threads/108117)

<div class="topic-metadata">

**Author:** [@TI36XPro](https://discourse.julialang.org/u/TI36XPro)\
**Replies:** 7\
**Last updated:** [December 28, 2023, 5:47pm UTC](https://discourse.julialang.org/t/question-about-new-gc-threads/108117 "2023-12-28T17:47:51Z")

</div>

I am excited to start using Julia 1.10.0 since I have a particular set of simulations which are allocation heavy (many small allocations) and I believe the GC is the current bottleneck. I want to make sure I am doing th…

---

## [Loop performance issue for a specific data size](https://discourse.julialang.org/t/loop-performance-issue-for-a-specific-data-size/107021)

<div class="topic-metadata">

**Author:** [@ReWoP](https://discourse.julialang.org/u/ReWoP)\
**Replies:** 2\
**Last updated:** [December 7, 2023, 6:10pm UTC](https://discourse.julialang.org/t/loop-performance-issue-for-a-specific-data-size/107021 "2023-12-07T18:10:07Z")

</div>

Hello everyone! I’m testing a population-based algorithm and have encountered performance issues, particularly when looping with large populations (i.e., using large data matrices). Everything works fine when using mat…

---

## [\[ANN\] AllocCheck.jl: Static code analysis to prove allocation-free behavior](https://discourse.julialang.org/t/ann-alloccheck-jl-static-code-analysis-to-prove-allocation-free-behavior/106414)

<div class="topic-metadata">

**Author:** [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Replies:** 27\
**Last updated:** [December 6, 2023, 10:56am UTC](https://discourse.julialang.org/t/ann-alloccheck-jl-static-code-analysis-to-prove-allocation-free-behavior/106414 "2023-12-06T10:56:02Z")

</div>

JuliaHub is happy to announce a new open source tool for static code analysis to prove that a Julia function is allocation-free. Use this to ensure that codes are safe for real-time applications, such as how we use it fo…

---

## [How to force an object to be freed by the garbage collector](https://discourse.julialang.org/t/how-to-force-an-object-to-be-freed-by-the-garbage-collector/77985)

<div class="topic-metadata">

**Author:** [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)\
**Replies:** 19\
**Last updated:** [October 26, 2023, 12:11pm UTC](https://discourse.julialang.org/t/how-to-force-an-object-to-be-freed-by-the-garbage-collector/77985 "2023-10-26T12:11:44Z")

</div>

From this very old post (https://groups.google.com/g/julia-users/c/QkChqeKnd9g/m/cqltIs5doQoJ) I was led to believe that the call to gc below would free the memory allocated by X, but it doesn’t. How could I force the r…

---

## [Estimate memory requirements of ODE solver](https://discourse.julialang.org/t/estimate-memory-requirements-of-ode-solver/104567)

<div class="topic-metadata">

**Author:** [@Salmon](https://discourse.julialang.org/u/Salmon)\
**Replies:** 7\
**Last updated:** [October 6, 2023, 2:57pm UTC](https://discourse.julialang.org/t/estimate-memory-requirements-of-ode-solver/104567 "2023-10-06T14:57:02Z")

</div>

Hi everyone, I am solving a very large (~10^8) system of ODE’s. I would like to use the VCABM solver from ordinaryDiffEq since that seems to be fastest, but I have memory issues that I would like to understand better. I…

---

## [Reduce GC time](https://discourse.julialang.org/t/reduce-gc-time/103736)

<div class="topic-metadata">

**Author:** [@fdekerme](https://discourse.julialang.org/u/fdekerme)\
**Replies:** 7\
**Last updated:** [September 14, 2023, 10:28am UTC](https://discourse.julialang.org/t/reduce-gc-time/103736 "2023-09-14T10:28:23Z")

</div>

Hello :grin:, I tried to optimize my code to reduce GC time. Among other things, I tried to implement “in place” operations, in particular with a long GC function “is\_intersect!”, which checks whether a given interval i…

---

## [Memory not released on HTTP POST requests?!](https://discourse.julialang.org/t/memory-not-released-on-http-post-requests/103336)

<div class="topic-metadata">

**Author:** [@sschmidhuber](https://discourse.julialang.org/u/sschmidhuber)\
**Replies:** 2\
**Last updated:** [August 30, 2023, 9:51pm UTC](https://discourse.julialang.org/t/memory-not-released-on-http-post-requests/103336 "2023-08-30T21:51:07Z")

</div>

Hello, I was trying to find a memory leak in my application, but now I think either it is in HTTP.jl or I’m doing some thing wrong… I created a test script to reproduce the issue (replace “path/to/a/large/file.iso” to …

---

## [Reference counting and disposables](https://discourse.julialang.org/t/reference-counting-and-disposables/98875)

<div class="topic-metadata">

**Author:** [@stemann](https://discourse.julialang.org/u/stemann)\
**Replies:** 4\
**Last updated:** [August 12, 2023, 8:56am UTC](https://discourse.julialang.org/t/reference-counting-and-disposables/98875 "2023-08-12T08:56:09Z")

</div>

In ResourcePools.jl/pooled\_abstract\_array.jl at feature/multi-threading · IHPSystems/ResourcePools.jl · GitHub, I have two concepts - in addition to pooled resources / pools of resources: Reference counted instances - …

---

## [Too much garbage collection for a simple vector addition operation](https://discourse.julialang.org/t/too-much-garbage-collection-for-a-simple-vector-addition-operation/102173)

<div class="topic-metadata">

**Author:** [@ducanh-le](https://discourse.julialang.org/u/ducanh-le)\
**Replies:** 12\
**Last updated:** [July 29, 2023, 7:16am UTC](https://discourse.julialang.org/t/too-much-garbage-collection-for-a-simple-vector-addition-operation/102173 "2023-07-29T07:16:02Z")

</div>

Hi everyone, I’m trying to optimize my code. When look at the profiler, the 2nd and the 3rd line below got GC flags: function resourceAvailable(v::Int32, a::Int32, usedResource::Vector{Int32}, md::ModelData) needed…

---

## [Multithreaded program hangs without explict GC.gc()](https://discourse.julialang.org/t/multithreaded-program-hangs-without-explict-gc-gc/99452)

<div class="topic-metadata">

**Author:** [@hayk](https://discourse.julialang.org/u/hayk)\
**Replies:** 6\
**Last updated:** [July 20, 2023, 7:35pm UTC](https://discourse.julialang.org/t/multithreaded-program-hangs-without-explict-gc-gc/99452 "2023-07-20T19:35:54Z")

</div>

I have the following code that uses Julia’s atomic variables and hangs if I do not use gc. I run the program with julia -t 6. I set two atomic variables to false, then spawn two threads that wait in a while loop for the…

---

## [Garbage collection not aggressive enough on Slurm Cluster](https://discourse.julialang.org/t/garbage-collection-not-aggressive-enough-on-slurm-cluster/61649)

<div class="topic-metadata">

**Author:** [@mkschleg](https://discourse.julialang.org/u/mkschleg)\
**Replies:** 17\
**Last updated:** [August 4, 2021, 2:11pm UTC](https://discourse.julialang.org/t/garbage-collection-not-aggressive-enough-on-slurm-cluster/61649 "2021-08-04T14:11:50Z")

</div>

I’ve been using slurm for awhile w/ julia. I’ve only recently been running into issues where I’m running out of memory for long running processes (like 30hrs). The jobs are highly regular, effectively calling the same fu…

---

## [This month in Julia world - 2023-05](https://discourse.julialang.org/t/this-month-in-julia-world-2023-05/99634)

<div class="topic-metadata">

**Author:** [@Krastanov](https://discourse.julialang.org/u/Krastanov)\
**Replies:** 20\
**Last updated:** [June 9, 2023, 10:04pm UTC](https://discourse.julialang.org/t/this-month-in-julia-world-2023-05/99634 "2023-06-09T22:04:04Z")

</div>

There was a call to action for someone to make a newsletter that lists interesting developments in the Julia world, in order to communicate improvements to the language that are not visible unless you track Github and Sl…

---

## [Heap-size-hint usage recommendations](https://discourse.julialang.org/t/heap-size-hint-usage-recommendations/98697)

<div class="topic-metadata">

**Author:** [@rssdev10](https://discourse.julialang.org/u/rssdev10)\
**Replies:** 3\
**Last updated:** [May 30, 2023, 3:20am UTC](https://discourse.julialang.org/t/heap-size-hint-usage-recommendations/98697 "2023-05-30T03:20:55Z")

</div>

Julia 1.9 got a new CLI option --heap-size-hint. See #45369 for details and Julia execution inside a container with restricted RAM This option allows to set a soft limit of memory consumption when the garbage collector …

---

## [Very different performance in different computers due to garbage collection?](https://discourse.julialang.org/t/very-different-performance-in-different-computers-due-to-garbage-collection/87563)

<div class="topic-metadata">

**Author:** [@TheLeache](https://discourse.julialang.org/u/TheLeache)\
**Replies:** 28\
**Last updated:** [May 12, 2023, 12:54pm UTC](https://discourse.julialang.org/t/very-different-performance-in-different-computers-due-to-garbage-collection/87563 "2023-05-12T12:54:26Z")

</div>

So, I have a code which calculates a measure of “openness” or “sprawl” around points in a series of big rasters from the National Land Cover Dataset. I had used this code on my personal laptop (A 2020 ROG G14 with a Ryze…

---

## [Do Garbage Collectors necessarily make code slow?](https://discourse.julialang.org/t/do-garbage-collectors-necessarily-make-code-slow/97902)

<div class="topic-metadata">

**Author:** [@FrancisKing](https://discourse.julialang.org/u/FrancisKing)\
**Replies:** 22\
**Last updated:** [April 27, 2023, 2:19pm UTC](https://discourse.julialang.org/t/do-garbage-collectors-necessarily-make-code-slow/97902 "2023-04-27T14:19:14Z")

</div>

A more serious question, while you’re around, is to ask you why C# is generally reckoned to be slower than C++, “because it has garbage collection”. In another thread you opined that garbage collectors don’t necessarily …

[Next page](https://discourse.julialang.org/tag/garbage-collection/358.md?match_all_tags=true&page=1&tags%5B%5D=garbage-collection)
