[erlang-questions] Erlang Memory Question

Robert Raschke rtrlists@REDACTED
Wed Sep 24 16:28:22 CEST 2014


I always thought that is one of the reasons to have processes.
If you've got something big you want to throw away quickly, make a process
for it.

$ erl
Erlang R16B03-1 (erts-5.10.4) [source] [64-bit] [smp:8:8]
[async-threads:10] [hipe] [kernel-poll:false]

Eshell V5.10.4  (abort with ^G)
1> erlang:memory().
[{total,14148416},
 {processes,4091608},
 {processes_used,4091488},
 {system,10056808},
 {atom,194289},
 {atom_used,172614},
 {binary,1514552},
 {code,4026600},
 {ets,262688}]
2> Pid = spawn(
2>   fun () ->
2>     X = binary:copy(<<1,2,3,4,5,6,7,8>>, 1024),
2>     Y = binary:copy(X, 1024),
2>     receive stop -> ok end
2>   end
2> ).
<0.35.0>
3> erlang:memory().
[{total,22643832},
 {processes,4203448},
 {processes_used,4203448},
 {system,18440384},
 {atom,194289},
 {atom_used,175110},
 {binary,9685320},
 {code,4221791},
 {ets,267056}]
4> Pid ! stop.
stop
5> erlang:memory().
[{total,13587776},
 {processes,4084496},
 {processes_used,4084384},
 {system,9503280},
 {atom,194289},
 {atom_used,175110},
 {binary,748144},
 {code,4221791},
 {ets,267056}]
6>


Regards,
Robby


On 24 September 2014 02:13, Eranga Udesh <eranga.erl@REDACTED> wrote:

> Well, yes I may deliberately lie.
>
> However my suggestion is to, instead of doing a full sweep by the garbage
> collector (GC) to identify data going out of scope and reclaim, can the
> program (or rather I) deliberately say I (the calling process) is finished
> using the said data, so the GC may free that part.
>
> Then the GC may carry out it's own logic, which it currently does to
> verify if the same data is referenced by any other processes, etc., and
> decide if to GC or not.
>
> = Eranga
>
> On Tue, Sep 23, 2014 at 12:42 PM, Richard A. O'Keefe <ok@REDACTED>
> wrote:
>
>>
>> On 23/09/2014, at 2:24 PM, Eranga Udesh wrote:
>>
>> > Thanks for the information received so far.
>> >
>> > Wouldn't it be good for Erlang to have a single object garbage
>> collection function/bif?
>>
>> NO.  In C it's called free() and it's a major cause of errors.
>>
>> > For example, when I no longer require a large object, I force to
>> garbage collect it, without making a full sweep?
>>
>> Why should the garbage collector *believe* you that the "object"
>> is free?  You could be deliberately lying.  You could (and
>> probably are) be mistaken.  How is it to know which bits you
>> want to keep without doing its usual thing?  In a shared heap
>> implementation (which Erlang has had and may have again) the
>> fact that *you've* finished with the object doesn't mean
>> everyone *else* has.  A meaningful operation should not depend
>> on implementation details like that.
>> >
>> > As mentioned in the document, a full sweep may degrade the performance.
>>
>> Not half as much as freeing too much would!
>>
>> This is micro-optimisation.  Avoid passing around large
>> objects in the first place.
>>
>>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140924/72265281/attachment.htm>


More information about the erlang-questions mailing list