# High Memory Usage

**URL:** <https://forum.modular.com/t/high-memory-usage/2086>\
**Category:** Mojo\
**Tags:** debugging\
**Created:** [August 6, 2025, 12:37pm UTC](https://forum.modular.com/t/high-memory-usage/2086 "2025-08-06T12:37:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![spacy](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@spacy](https://forum.modular.com/u/spacy)\
**Post date:** [August 6, 2025, 12:37pm UTC](https://forum.modular.com/t/high-memory-usage/2086/1 "2025-08-06T12:37:54Z")

</div>

Hi,

This code when compiled with `mojo build` uses 19M of memory according to htop (and 2G of virtual memory) on Linux amd64.  
What are the reasons for this imho high memory usage?  
Anything I can do to bring it down?  
Thanks.

```mojo
from time import sleep

fn main():
  while True:
    print(“hello”)
    sleep(5.0)

```

---

<div class="post-metadata">

**Author:** ![owenhilyard](https://sea1.discourse-cdn.com/flex001/user_avatar/forum.modular.com/owenhilyard/32/41_2.png) [@owenhilyard](https://forum.modular.com/u/owenhilyard)\
**Post date:** [August 6, 2025, 12:44pm UTC](https://forum.modular.com/t/high-memory-usage/2086/2 "2025-08-06T12:44:38Z")

</div>

The resident 19M is likely due to how the allocator works. Mojo’s runtime does do some allocation up front for various things like wrappers around stdin/stdout, storing which cores are pcores on Intel CPUs, etc. `tcmalloc`, Mojo’s allocator, is designed to minimize fragmentation and have good multi-threaded throughput, which means that it creates decent sized per-core caches. Most of that memory resident memory usage is likely coming from there.

The 2 GB of virtual memory is lazily handed over by the kernel, since tcmalloc requests a decent chunk of memory up front so it doesn’t need to do that expensive operation again for short-lived allocations. Unless you actually touch that memory, it doesn’t matter except as a bit of book keeping work for the kernel.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex001/uploads/modular/original/1X/2751e0fbdc595a99718b216730957e9db4448cfd.jpeg) [@system](https://forum.modular.com/u/system)\
**Post date:** [February 2, 2026, 12:45pm UTC](https://forum.modular.com/t/high-memory-usage/2086/3 "2026-02-02T12:45:26Z")

</div>

Closed on February 2, 2026, 12:45pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
