Avoiding cloning messages

Hi all,

I just read Cloning messages in a flow. Whats the best pratice on flat flows to avoid message cloning? should I code functions this way:

image

Thank you!

You are right - to send a message without it being cloned, use node.send(msg, false).

This only stops it cloning the message to the first node it is wired to. If it is wired to multiple nodes, then the 2nd (and subsequent) nodes will receive a clone of the message object.

1 Like

Thank you @knolleary.

Is there a difference between that and return msg? I thought that also doesn't clone if there is only one output wired.

Yes, you are right - I had to double check because the blog post doesn't explicitly say so.

return msg will not clone the message passed to the first wired node.

1 Like

so, theres no difference between both methods?

node.send(msg, false);
return null;

and

return msg;

Correct, no difference. The purpose of node.send(msg, false) is for where you need to use node.send(), which does clone by default, but don't want it to clone. Often when using node.send you do want it to clone in order to avoid sending the same message multiple times, which can cause problems, as if a later node changes the message contents then that would change the original msg that then may get sent again.

1 Like

Thanks @Colin. :smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.