# Crystal compiler utilizes 500MB~ ram after compiling is complete

**URL:** <https://forum.crystal-lang.org/t/crystal-compiler-utilizes-500mb-ram-after-compiling-is-complete/1635>\
**Category:** Help & Support\
**Created:** [January 17, 2020, 4:24am UTC](https://forum.crystal-lang.org/t/crystal-compiler-utilizes-500mb-ram-after-compiling-is-complete/1635 "2020-01-17T04:24:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![girng\_github](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/girng_github/32/571_2.png) [@girng\_github](https://forum.crystal-lang.org/u/girng_github)\
**Post date:** [January 17, 2020, 4:24am UTC](https://forum.crystal-lang.org/t/crystal-compiler-utilizes-500mb-ram-after-compiling-is-complete/1635/1 "2020-01-17T04:24:56Z")

</div>

I mentioned this in gitter last week or so, but I think the lead devs should be aware of it. I don’t think it’s normal behavior (might be a bug).

When executing `crystal app.cr`, the memory usage will shoot up about 500MB of ram (normal because the compiler uses it), but then after your app has started, that memory is still allocated. In fact, all the processes of the compiler are still running

I’m trying to find a workaround where we can compile our Crystal app, then execute it without the compiler still running.

I’ve got a MasterServer.cr that eats up around 500MB, then my GameServer that eats up another 500MB while only having 8GB of total ram.

My GameServer and MasterServer apps only utilize **several MBs of ram when executed without the compiler in the background**. This is how it should be after the compiler has finished, right?

I was thinking of something like

```auto
crystal build src/GameServer.cr --release && ./GameServer

```

But don’t know how to cancel the compiler processes through commands cause it has a list of PIDs

I’ve tested this on native Debian 9, and WSL’s Ubuntu

### Screenshots

- no compiler in the background:  

- compiler processes still in background:  

edit: Or, maybe a compiler flag that automatically kills all the compiler processes after compilation is done? Not sure, just thinking out loud

---

<div class="post-metadata">

**Author:** ![bew](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/bew/32/113_2.png) [@bew](https://forum.crystal-lang.org/u/bew)\
**Post date:** [January 17, 2020, 9:01am UTC](https://forum.crystal-lang.org/t/crystal-compiler-utilizes-500mb-ram-after-compiling-is-complete/1635/2 "2020-01-17T09:01:58Z")

</div>

`crystal build src/GameServer.cr --release && ./GameServer`  
Is the way to go, once the build ends the memory used by the compiler will be freed and your gameserver can run by itself.

---

<div class="post-metadata">

**Author:** ![girng\_github](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/girng_github/32/571_2.png) [@girng\_github](https://forum.crystal-lang.org/u/girng_github)\
**Post date:** [January 17, 2020, 11:08pm UTC](https://forum.crystal-lang.org/t/crystal-compiler-utilizes-500mb-ram-after-compiling-is-complete/1635/3 "2020-01-17T23:08:46Z")

</div>

Wow, that’s weird. Yesterday when I tried that command, `htop` kept showing the lingering compiler processes. Now, when I use `top` those compiler processes are no longer there and it seems to work. Wtf

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/rogerdpack/32/117_2.png) [@rogerdpack](https://forum.crystal-lang.org/u/rogerdpack)\
**Post date:** [January 22, 2020, 8:02am UTC](https://forum.crystal-lang.org/t/crystal-compiler-utilizes-500mb-ram-after-compiling-is-complete/1635/4 "2020-01-22T08:02:39Z")

</div>

Yeah I’ve noticed that before too. It doesn’t exec the new process but just runs it “in case you have a flag set to output debug info” (i.e. statistics on how long it took to run). It surprised me. Maybe it should `exec` if that flag isn’t set hmm… :)

> <https://github.com/crystal-lang/crystal/blob/master/src/compiler/crystal/command.cr#L217>
