[erlang-questions] Tail recursion and memory leak

Peter Lemenkov <>
Fri Mar 16 13:04:54 CET 2007


2007/3/16, Christian S <>:

> You dont need to call lists:append, gen_udp:send will behave as if it
> calls erlang:iolist_to_binary/1. In fact, we call them iolists because
> most io functions behaves this way.

OK, I changed send_message a little:

===========================
send_msg (Fd,Caller,Called,UserName,SessionID,TagTo,TagFrom,Route) ->
        ok = gen_udp:send(Fd,"127.0.0.1",5060,
        "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: MyApp\r\n"
        "CSeq: 123 BYE\r\n"
        "Route: <" ++ Route ++ ">\r\n"
        "Content-Length: 0\r\n"
        "\r\n").

===========================

Memory is still consumes until the system completely runs out of mem.
According to the top utility:
19705 root      15   0 30924  10m 1852 S    3  0.5   0:00.24 beam
19705 root      15   0 29900   9m 1852 S    0  0.5   0:00.24 beam
19705 root      16   0 46928  22m 1856 S   10  1.1   0:00.53 beam
19705 root      18   0 99.7m  61m 1856 S   98  3.0   0:03.48 beam
19705 root      25   0  150m 125m 1856 S   98  6.3   0:06.41 beam
19705 root      25   0  129m  92m 1856 R   94  4.6   0:09.24 beam
19705 root      25   0  118m  91m 1856 R   93  4.5   0:12.04 beam
19705 root      25   0  129m 106m 1856 R   96  5.3   0:14.92 beam
19705 root      25   0  195m 121m 1856 R   91  6.1   0:17.66 beam
19705 root      25   0  207m 136m 1856 R   91  6.8   0:20.41 beam
19705 root      19   0  176m 133m 1856 S   93  6.7   0:23.21 beam
19705 root      25   0  166m 132m 1856 S   95  6.6   0:26.06 beam
19705 root      19   0  166m 138m 1856 R   93  6.9   0:28.85 beam
19705 root      25   0  172m 147m 1856 R   94  7.3   0:31.69 beam
19705 root      25   0  189m 152m 1856 R   94  7.6   0:34.52 beam
19705 root      21   0  180m 155m 1856 R   93  7.7   0:37.33 beam
19705 root      25   0  398m 300m 1856 R   91 14.9   0:40.08 beam
19705 root      25   0  249m 164m 1856 R   95  8.2   0:42.95 beam
19705 root      25   0  257m 163m 1856 R   95  8.1   0:45.81 beam
19705 root      25   0  297m 201m 1856 R   96 10.0   0:48.69 beam
19705 root      25   0  242m 174m 1856 R   93  8.7   0:51.49 beam
19705 root      25   0  248m 175m 1856 R   92  8.7   0:54.27 beam
19705 root      25   0  280m 208m 1856 R   94 10.4   0:57.09 beam
19705 root      25   0  263m 199m 1856 R   94  9.9   0:59.91 beam
19705 root      25   0  242m 191m 1856 R   95  9.5   1:02.76 beam
19705 root      25   0  233m 193m 1856 R   94  9.6   1:05.59 beam
19705 root      25   0  237m 197m 1856 R   94  9.8   1:08.42 beam
19705 root      25   0  246m 208m 1856 R   95 10.4   1:11.27 beam
19705 root      25   0  249m 215m 1856 R  100 10.7   1:14.28 beam
19705 root      25   0  240m 213m 1856 R   99 10.6   1:17.24 beam
19705 root      25   0  463m 402m 1856 R   99 20.0   1:20.22 beam
19705 root      25   0  265m 217m 1856 R   99 10.8   1:23.20 beam
19705 root      25   0  266m 226m 1856 R  100 11.3   1:26.19 beam
19705 root      25   0  266m 235m 1856 R  100 11.7   1:29.18 beam
19705 root      25   0  266m 244m 1856 R  100 12.2   1:32.18 beam
19705 root      25   0  373m 225m 1856 R   99 11.2   1:35.16 beam
19705 root      16   0  372m 233m 1856 R   95 11.6   1:38.02 beam
19705 root      17   0  373m 241m 1856 R   98 12.0   1:40.96 beam
19705 root      21   0  373m 249m 1856 S   98 12.4   1:43.90 beam
19705 root      25   0  373m 236m 1856 R   97 11.8   1:46.81 beam
19705 root      25   0  373m 245m 1856 R   96 12.2   1:49.70 beam
19705 root      25   0  435m 289m 1856 R   97 14.4   1:52.62 beam
19705 root      25   0  349m 247m 1856 R   97 12.3   1:55.55 beam
19705 root      25   0  381m 270m 1856 R   97 13.4   1:58.47 beam
19705 root      25   0  354m 252m 1856 R   97 12.6   2:01.38 beam
19705 root      25   0  354m 260m 1856 R   96 13.0   2:04.26 beam
19705 root      25   0  343m 257m 1856 R   97 12.8   2:07.17 beam

================

and so on.

On the other hand, if I try to write simple string (w/o concatenation)
everything looks fine.

-- 
With best regards!



More information about the erlang-questions mailing list