itinance / itinance/react-native-fs

BUG: Probably a memory leak

Open
#920 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
5k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

I'm using `begin` and `progress` callbacks while downloading a file and sometimes users can cancel a download. The problem I was noticing is that the application became slower over the time (slow interaction, slow UI) when we were canceling downloads and I guess I've found why.

https://github.com/itinance/react-native-fs/blob/f2f8f4a058cd9acfbcac3b8cf1e08fa1e9b09786/FS.common.js#L539

```javascript
return {
jobId,
promise: RNFSManager.downloadFile(bridgeOptions).then(res => {
subscriptions.forEach(sub => sub.remove()); // <------------------------ subscriptions are removed only if download is complete
return res;
})
.catch(e => {
return Promise.reject(e); // <------------------------ if we cancel a download, subscriptions are not removed
})
};
```

at the end of `downloadFile` function, we see that our callbacks are removed ONLY when the download is completed. But if we cancel, it never gets removed from the list. Therefore, we when start a new download, the list is filled another time. So whenever we cancel a download and start another one, it fills the list over and over again. And then, we can feel the application is slow.

Could also explains #906

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.