<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Mar 25, 2021, 5:44 PM Valentin Micic <<a href="mailto:v@micic.co.za">v@micic.co.za</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space">Hi,<div><br></div><div>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><br></div><div>As an example, consider a following code snippet:</div><div><br></div><div><span style="font-family:Menlo;font-size:11px">ReqRef = make_ref(),</span></div><div><font face="Menlo"><span style="font-size:11px">SomeServerPid ! {request, {ReqRef, [arg1, arg2, . . ., argn]} ),</span></font></div><div><span style="font-family:Menlo;font-size:11px">Ref = erlang:send_after( 5000, self(), {cancel, ReqRef} ),</span></div><div><span style="font-family:Menlo;font-size:11px"><br></span></div><div><font face="Menlo"><span style="font-size:11px">receive</span></font></div><div><font face="Menlo"><span style="font-size:11px">   {ReqRef, some_reply}</span></font></div><div><font face="Menlo"><span style="font-size:11px">   -></span></font><span style="font-family:Menlo;font-size:11px"> </span></div><div><font face="Menlo"><span style="font-size:11px">       erlang:cancel_timer(Ref),</span></font></div><div><font face="Menlo"><span style="font-size:11px">       some_reply</span></font></div><div><font face="Menlo"><span style="font-size:11px">   ;</span></font></div><div><font face="Menlo"><span style="font-size:11px">   {cancel, ReqRef}</span></font></div><div><font face="Menlo"><span style="font-size:11px">   -></span></font></div><div><font face="Menlo"><span style="font-size:11px">        “Request Timeout!”</span></font></div><div><font face="Menlo"><span style="font-size:11px">end</span></font></div><div><font face="Menlo"><span style="font-size:11px"><br></span></font></div><div>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>As I never really critically examined this claim, is there anyone that may have a different opinion regarding this.</div><div><br></div><div>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 </div></div></blockquote></div></div><div dir="auto"><br></div><div dir="auto">How do we <b>ignore</b> the messages?</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space"><div>generated by send_after/3 instead of canceling it?</div><div><br></div><div>Kind regards</div><div><br></div><div>V/</div></div></blockquote></div></div><div dir="auto"><br></div><div dir="auto"><br><span style="font-family:sans-serif">नमस्ते।</span><br style="font-family:sans-serif"><span style="font-family:sans-serif">नलिन रंजन</span><br></div><div dir="auto"></div></div>