[erlang-questions] how to debug memory leaks?

Robert Virding <>
Sun Dec 5 01:32:51 CET 2010


----- "Alain O'Dea" <> wrote:
> 
> The obvious culprits for memory leaks in Erlang for me have been:
> - creating atoms dynamically
> - storing large structures in the process dictionary
> - behavior state data grows unboundedly (storing a growing list or
> proplist for example)
> - large binaries are shared across processes under the hood
> 
> The obvious fixes for me have been:
> - avoid dynamically creating atoms (use list_to_existing_atom/1 or
> binary_to_existing_atom/1)
> - avoid using the process dictionary (make sure to clear keys you no
> longer need if you do use it)

This advice is equally valid for dict's, gb_trees and ets tables as well. Continually creating new keys without removing old unused ones will eventually do you.

> - avoid growing behaviour state (use a persistence solution like
> Riak)
> - avoid large binaries

Large binaries are tricky in that sometimes they are just solution you need to get your app to work properly, and sometimes they will ruin your memory usage.

Robert


More information about the erlang-questions mailing list