[erlang-questions] Erlang Memory Question

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Mon Sep 22 19:56:11 CEST 2014


In general: No it won't. GC will trigger once the process has allocated
enough data. If your processing is allocating enough data, this will
quickly happen and you don't have to worry. If not, you may have to gently
persuade the process to do so. There are several ways:

* Set fullsweep_after on the process with a low value (0) and run
erlang:garbage_collect()
* Go through a hibernation with an immediate wakeup (feels ugly to me)
* Handle fetching and extraction in a separate process and send the
extracted part 'x' back as a message. This will free up memory almost
immediately for other processes to use (simple and elegant)
* Don't fetch the large object in the first place, but make it possible to
ask for an extraction only. Or stream data a bit at a time and handle the
stream in chunks rather than everything at once.


On Mon, Sep 22, 2014 at 4:11 PM, Eranga Udesh <eranga.erl@REDACTED> wrote:

> Hi,
>
> I'm trying to optimize my memory consumption in Erlang VM and to garbage
> collect as soon as possible.
>
> Let's say I have a large object, "X", After some processing, I only need
> to work on small part of X, called "x".
>
> Can someone advice me if below process flow will put the large object X in
> to garbage collection, while waiting for the long running job to continue?
>
> function1() ->
>
> X = ... fetch a large object....
>
> ... some processing...
>
> x = ... extract a part of X...
> ... long running job....
>
>
> If it's not putting X into garbage collection, does below change do that?
>
> function1() ->
>
> X = ... fetch a large object....
>
> ... some processing...
>
> x = ... extract a part of X...
> function2(x).
>
> function2(x) ->
>
> ... long running job...
>
>
> Tks,
> - Eranga
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>


-- 
J.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140922/171d895d/attachment.htm>


More information about the erlang-questions mailing list