jakesgordon / javascript-state-machine

A javascript finite state machine library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

shifting the events object may lead to memory leak on certain smartTVs

OrenMe opened this issue · comments

The events array shifting here:

if (observers.length === 0) {
events.shift();
return this.observeEvents(events, args, event, previousResult);
}

can result in memory allocation leak in some smartTVs(I won't specify the make and model, as it seems like a nasty security bug, which I opened an issue already on).
As the array shift method preforms the operation on the array object itself then it may lead to memory allocation problems in certain circumstances.
Is there a reason to favour Array.shift over doing const restEvents = events.slice(1); ?
The slice operation creates a new array object and I can only assume that it is not affected from the same implementation bug in the JS engine on the aforementioned smartTVs.
This also avoids passing the events object by ref which might also be good idea to avoid the referencing between calls, although I know nothing touches it at the moment so there's no real issue.