<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi,<div class=""><br class=""></div><div class="">Usually, when I use erlang:send_after/3, but no longer need the “ordered" event, I issue a corresponding erlang:cancel_timer/1 to stop this event from being raised.</div><div class=""><br class=""></div><div class="">As an example, consider a following code snippet:</div><div class=""><br class=""></div><div class=""><span style="font-family: Menlo; font-size: 11px;" class="">ReqRef = make_ref(),</span></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">SomeServerPid ! {request, {ReqRef, [arg1, arg2, . . ., argn]} ),</span></font></div><div class=""><span style="font-family: Menlo; font-size: 11px;" class="">Ref = erlang:send_after( 5000, self(), {cancel, ReqRef} ),</span></div><div class=""><span style="font-family: Menlo; font-size: 11px;" class=""><br class=""></span></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">receive</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class=""> {ReqRef, some_reply}</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class=""> -></span></font><span style="font-family: Menlo; font-size: 11px;" class=""> </span></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class=""> erlang:cancel_timer(Ref),</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class=""> some_reply</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class=""> ;</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class=""> {cancel, ReqRef}</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class=""> -></span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class=""> “Request Timeout!”</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class="">end</span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class=""><br class=""></span></font></div><div class="">This is what I usually do, because I believed that it would be more cost effective to cancel the timer than to ignore the message ordered by send_after/3.</div><div class="">As I never really critically examined this claim, is there anyone that may have a different opinion regarding this.</div><div class=""><br class=""></div><div class="">Put differently, ensuring that no memory leak is possible (due to general nature of the code handling messages), would it be “cheaper" to ignore the message generated by send_after/3 instead of canceling it?</div><div class=""><br class=""></div><div class="">Kind regards</div><div class=""><br class=""></div><div class="">V/</div></body></html>