Cannot allocate 441485240 bytes of memory (of type "old_heap")

hi, i am following this tutorial , but when run the MIX_ENV=prod mix phoenix.digest getting error like follow what mistake i made

Generated comeonin app
==> sweet_xml
Compiling 1 file (.ex)
Generated sweet_xml app  
==> ex_phone_number
Compiling 21 files (.ex)
Compiling lib/ex_phone_number/metadata.ex (it's taking more than 10s)
Crash dump is being written to: erl_crash.dump...done
eheap_alloc: Cannot allocate 441485240 bytes of memory (of type "old_heap").
1 Like

How much memory has the machine you are trying this? Do you have any ulimits regarding memory consumption set?

The message basically means that the BEAM wasn’t able to request more memory from the operating system.

I am new to aws, when i run free -m


total       used       free     shared    buffers     cached
Mem:           993        136        856          0          8         41
-/+ buffers/cache:         86        906
Swap:            0          0          0

when i run df -h

Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        489M   56K  488M   1% /dev
 tmpfs           497M     0  497M   0% /dev/shm
 /dev/xvda1      7.8G  2.5G  5.2G  33% /

how to resolve this?

That’s it. Your machine has about a singe GiB of ram, ~850 MiB of it are currently available. So your message in the OP said it wasn’t able to allocate about 400 MiB. Taking into account that there might have been other processes taking up memory as well and also stuff in the bin_heap, I can say for sure, that your machine has not enough memory to build at least that library ex_phone_number.

Try to build your application locally into a release, embed the ERTS and deploy the archive.

Alternatively, stock up the memory of your machine. Perhaps you can stock to 4 GiB for build and lower back to 1 GiB during run time through AWS interface? I heard you can manage your instances “flexible” there, but I’m not sure what it means. I haven’t worked with AWS or similar services so far…

Try to build your application locally into a release, embed the ERTS and deploy the archive.

Thumbs up! That is the way to do it. Building software can usually be
memory hungry (and I think building releases especially (and dialyzer))
so you really want to build locally and then deploy on yoru AWS

I have to admit, that this still has downsides.

AWS runs on 64bit linux and we do not know anything about the OPs system. Maybe he is running on windows, arm, or 32bit (or even combinations thereof). And especially the last two things do make it near to impossible to prepare the release locally.

Yeah, it looks like ex_phone_number is really hungry for memory during compilation :worried: Elixir 1.5 should use a bit less memory during compilation (and compile faster), but I’m not sure it’s going to matter here.

or you can add swap to get through the build phase - that is sometimes needed if you build on memory limited machines.

I’'m not on aws but maybe this one