[erlang-questions] Tail recursion and memory leak

Chandru <>
Sat Mar 17 10:20:50 CET 2007


On 16/03/07, Peter Lemenkov <> wrote:
> Hello All!
> I write simple example of tail recursion:
>
<snip>

> No memory leaks - all worked as I want.
> However then I try to change function send_msg to something more
> valuable, for example:
>
> ==================
>        Msg = lists:append([    "BYE sip:127.0.0.1:5060 SIP/2.0 \r\n",
>                                "Via: SIP/2.0/UDP 127.0.0.1:3456\r\n",
>                                "From: <", Caller, ">;tag=", TagFrom, "\r\n",
>                                "To: <",  Called, ">;tag=", TagTo, "\r\n",
>                                "Call-ID: ", SessionID, "\r\n",
>                                "User-Agent: My User Agent\r\n",
>                                "CSeq: 123 BYE\r\n",
>                                "Route: <", Route, ">\r\n",
>                                "Content-Length: 0\r\n",
>                                "\r\n"]),
> %       io:format("~s~n", [Msg]).
>
>         ok = gen_udp:send(Fd,"127.0.0.1",5060, [Msg]).
>
> ==================
>
> I've got a huge memory consumption.
> Looks like I missed something important about string manipulating but
> I can't find out what exactly.
>

Is it possible that your destination is responding to you and those
messages are stacking up in you r message queue? The way you have
opened your UDP socket, the {active, true} option would be set by
default on your socket and any UDP packets arriving will be delivered
to your process message queue.

Repeat the experiment by opening the socket as follows:

gen_udp:open(3456, [{active, false}]).

regards,
Chandru



More information about the erlang-questions mailing list