JMPerez / spotify-web-api-js

A client-side JS wrapper for the Spotify Web API
https://jmperezperez.com/spotify-web-api-js/
MIT License
1.86k stars 260 forks source link

Possible memory leak #195

Closed christinna9031 closed 2 years ago

christinna9031 commented 3 years ago

I call getMyCurrentPlaybackState() every second to detect whenever user changes the track. I tried using both setInterval and setTimeout (with clearTimeout as well), but it seems to be leaking memory and crashes the whole page after 5-6h of running nonstop in a browser. Memory consumption just goes up indefinitely until it crashes. Any idea how to fix that?

JMPerez commented 2 years ago

Hi @christinna9031, sorry I didn't get back to this earlier. Did you manage to fix it?

It's unlikely that the problem is in this library, as it barely makes a http request to Spotify's API.

One thing that can cause it is if you are calling getMyCurrentPlaybackState()before a previous call to that function returns, either successfully or with an error. Otherwise there can be a long stack of pending requests piling up.

christinna9031 commented 2 years ago

The memory leak is still happening, I had to reduce the getMyCurrentPlaybackState() API calls to the bare minimum. I'm also looking into polling the API on server side and extending websocket to the client instead.