<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">If garbage collection isn't happening
      quick enough, you can generate the problematic data within a
      temporary process to make the temporary process' death trigger
      garbage collection naturally.  Doing that is a natural way to
      approach it.  The tuning is something additional that is
      optional.  I have a module I had used in the past to be as harsh
      as possible to the garbage collector (i.e., force it as much as
      possible) here
      <a class="moz-txt-link-freetext" href="https://gist.github.com/okeuday/dee991d580eeb00cd02c">https://gist.github.com/okeuday/dee991d580eeb00cd02c</a> but I don't
      think it is necessary with a decent architecture in-place (being
      that harsh shouldn't be necessary).  If you need to check the
      memory consumption of your processes
      <a class="moz-txt-link-freetext" href="http://www.erlang.org/doc/man/instrument.html">http://www.erlang.org/doc/man/instrument.html</a> is very helpful.<br>
      <br>
      On 09/22/2014 07:24 PM, Eranga Udesh wrote:<br>
    </div>
    <blockquote
cite="mid:CALg+e6yA6LopXvpEwxgzSzz8gBR78dfrrr89g3ju17vh0pgEqw@mail.gmail.com"
      type="cite">
      <div dir="ltr">Thanks for the information received so far.
        <div><br>
        </div>
        <div>Wouldn't it be good for Erlang to have a single object
          garbage collection function/bif? For example, when I no longer
          require a large object, I force to garbage collect it, without
          making a full sweep?</div>
        <div><br>
        </div>
        <div>As mentioned in the document, a full sweep may degrade the
          performance.</div>
        <div><br>
        </div>
        <div>- Eranga</div>
      </div>
      <div class="gmail_extra"><br>
        <div class="gmail_quote">On Tue, Sep 23, 2014 at 12:10 AM,
          Björn-Egil Dahlberg <span dir="ltr"><<a
              moz-do-not-send="true"
              href="mailto:wallentin.dahlberg@gmail.com" target="_blank">wallentin.dahlberg@gmail.com</a>></span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div dir="ltr">It should suffice by running an
              erlang:garbage_collect/0 directly after extracting some
              parts of the structure:
              <div><br>
              </div>
              <div>
                <div style="font-family:arial,sans-serif;font-size:13px">
                  <div>function1() -></div>
                  <div>
                    <blockquote style="margin:0px 0px 0px
                      40px;border:none;padding:0px">X1 = ... fetch a
                      large object ....</blockquote>
                    <blockquote style="margin:0px 0px 0px
                      40px;border:none;padding:0px">... some
                      processing...</blockquote>
                    <blockquote style="margin:0px 0px 0px
                      40px;border:none;padding:0px">X2 = ... extract a
                      part of X1 ...<br>
                      erlang:garbage_collect(),<br>
                      ... long running job....<br>
                    </blockquote>
                  </div>
                  <div><br>
                  </div>
                  <div>As long as the object of X1 is not referenced by
                    the process after the explicit call to the gc,
                    you're fine.</div>
                  <div>Note also, an explicit call to garbage_collect/0
                    will always to a 'fullsweep'.</div>
                  <div><br>
                  </div>
                  <div>Ofc, as Jesper mentioned, the it's probably
                    preferable not to fetch the whole object if
                    possible.</div>
                  <span class="HOEnZb"><font color="#888888">
                      <div><br>
                      </div>
                      <div>// Björn-Egil</div>
                      <div><br>
                      </div>
                    </font></span></div>
              </div>
            </div>
            <div class="HOEnZb">
              <div class="h5">
                <div class="gmail_extra"><br>
                  <div class="gmail_quote">2014-09-22 19:56 GMT+02:00
                    Jesper Louis Andersen <span dir="ltr"><<a
                        moz-do-not-send="true"
                        href="mailto:jesper.louis.andersen@gmail.com"
                        target="_blank">jesper.louis.andersen@gmail.com</a>></span>:<br>
                    <blockquote class="gmail_quote" style="margin:0 0 0
                      .8ex;border-left:1px #ccc solid;padding-left:1ex">
                      <div dir="ltr">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:
                        <div><br>
                        </div>
                        <div>* Set fullsweep_after on the process with a
                          low value (0) and run erlang:garbage_collect()</div>
                        <div>* Go through a hibernation with an
                          immediate wakeup (feels ugly to me)</div>
                        <div>* 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)</div>
                        <div>* 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.</div>
                        <div><br>
                        </div>
                      </div>
                      <div class="gmail_extra"><br>
                        <div class="gmail_quote">
                          <div>
                            <div>On Mon, Sep 22, 2014 at 4:11 PM, Eranga
                              Udesh <span dir="ltr"><<a
                                  moz-do-not-send="true"
                                  href="mailto:eranga.erl@gmail.com"
                                  target="_blank">eranga.erl@gmail.com</a>></span>
                              wrote:<br>
                            </div>
                          </div>
                          <blockquote class="gmail_quote"
                            style="margin:0 0 0 .8ex;border-left:1px
                            #ccc solid;padding-left:1ex">
                            <div>
                              <div>
                                <div dir="ltr">Hi,
                                  <div><br>
                                  </div>
                                  <div>I'm trying to optimize my memory
                                    consumption in Erlang VM and to
                                    garbage collect as soon as possible.</div>
                                  <div><br>
                                  </div>
                                  <div>Let's say I have a large object,
                                    "X", After some processing, I only
                                    need to work on small part of X,
                                    called "x".</div>
                                  <div><br>
                                  </div>
                                  <div>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?</div>
                                  <div><br>
                                  </div>
                                  <div>
                                    <div>function1() -></div>
                                    <div>
                                      <blockquote style="margin:0px 0px
                                        0px
                                        40px;border:none;padding:0px">X
                                        = ... fetch a large object....</blockquote>
                                      <blockquote style="margin:0px 0px
                                        0px
                                        40px;border:none;padding:0px">...
                                        some processing...</blockquote>
                                      <blockquote style="margin:0px 0px
                                        0px
                                        40px;border:none;padding:0px">x
                                        = ... extract a part of X...<br>
                                        ... long running job....<br>
                                      </blockquote>
                                    </div>
                                  </div>
                                  <div><br>
                                  </div>
                                  <div>If it's not putting X into
                                    garbage collection, does below
                                    change do that?</div>
                                  <div><br>
                                  </div>
                                  <div>function1() -></div>
                                  <div>
                                    <blockquote style="margin:0px 0px
                                      0px 40px;border:none;padding:0px">
                                      <div>X = ... fetch a large
                                        object....</div>
                                    </blockquote>
                                    <blockquote style="margin:0px 0px
                                      0px 40px;border:none;padding:0px">
                                      <div>... some processing...</div>
                                    </blockquote>
                                    <blockquote style="margin:0px 0px
                                      0px 40px;border:none;padding:0px">x
                                      = ... extract a part of X...<br>
                                      function2(x).<br>
                                      <br>
                                    </blockquote>
                                    function2(x) -></div>
                                  <div>
                                    <blockquote style="margin:0px 0px
                                      0px 40px;border:none;padding:0px">
                                      <div>... long running job...</div>
                                    </blockquote>
                                    <br>
                                  </div>
                                  <div>Tks,</div>
                                  <div>- Eranga</div>
                                </div>
                                <br>
                              </div>
                            </div>
_______________________________________________<br>
                            erlang-questions mailing list<br>
                            <a moz-do-not-send="true"
                              href="mailto:erlang-questions@erlang.org"
                              target="_blank">erlang-questions@erlang.org</a><br>
                            <a moz-do-not-send="true"
                              href="http://erlang.org/mailman/listinfo/erlang-questions"
                              target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
                            <br>
                          </blockquote>
                        </div>
                        <span><font color="#888888"><br>
                            <br clear="all">
                            <div><br>
                            </div>
                            -- <br>
                            J.
                          </font></span></div>
                      <br>
                      _______________________________________________<br>
                      erlang-questions mailing list<br>
                      <a moz-do-not-send="true"
                        href="mailto:erlang-questions@erlang.org"
                        target="_blank">erlang-questions@erlang.org</a><br>
                      <a moz-do-not-send="true"
                        href="http://erlang.org/mailman/listinfo/erlang-questions"
                        target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
                      <br>
                    </blockquote>
                  </div>
                  <br>
                </div>
              </div>
            </div>
          </blockquote>
        </div>
        <br>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
erlang-questions mailing list
<a class="moz-txt-link-abbreviated" href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a>
<a class="moz-txt-link-freetext" href="http://erlang.org/mailman/listinfo/erlang-questions">http://erlang.org/mailman/listinfo/erlang-questions</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>