react-native-youtube-iframe icon indicating copy to clipboard operation
react-native-youtube-iframe copied to clipboard

MaxListenersExceededWarning: Possible EventEmitter memory leak detected.

Open yasintz opened this issue 4 years ago • 4 comments

Describe the bug I am running getCurrentTime 2 times per second and so gives the error.

[MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 
11 getCurrentTime listeners added. Use emitter.setMaxListeners() to increase limit]

To Reproduce I'm running a setInterval in useEffect. Sometimes I get the above error. I think it's caused by the EventEmitter.

Smartphone (please complete the following information):

  • Device: General Mobile GM 9 pro
  • OS + version: Android 9
  • react-native-youtube-iframe 1.4.0
  • react-native-webview 11.0.0

yasintz avatar Dec 08 '20 10:12 yasintz

Hey this is due to queries to getCurrentTime() BEFORE the onReady() callback.

Can you try starting the setInterval() after onReady() is called?

LonelyCpp avatar Dec 08 '20 11:12 LonelyCpp

something like this -

const [playerReady, setPlayerReady] = useState(false);

useEffect(() => {
  let timer;
  if(playerReady) {
    timer = setInterval(() => { ... }, 500);
  }

  return () => clearInterval(timer);
}, [playerReady]);

return (
  <YoutubeIframe
    ...
    onReady={() => setPlayerReady(true);
  />
);

LonelyCpp avatar Dec 08 '20 11:12 LonelyCpp

@LonelyCpp I do it that way too. but it still gives this warning.

yasintz avatar Dec 08 '20 17:12 yasintz

As this problem persists, I reopened this issue. I am using FlatList and call getCurrrentTime with setInterval. This error happens after a while. How can I dissolve? Also, I'm using playerReady state as you said. @LonelyCpp

yasintz avatar Dec 16 '20 13:12 yasintz