react-native-fs
react-native-fs copied to clipboard
[BUGS:] Memory leak and application crash on reading a large file
Hi !
Problem: Memory leak and application crash System: react-native: 0.59.9 react: 16.9.0 react-native-fs: 2.14.1 iPad: 12.1 Xcode: 11.0
I can’t understand why there is a memory leak and application crash when reading a large file using the read() function
Example test code:
onReadAssets = async () => {
const url = ${node.asset.url}
// <—— Large file
for (let i = 0; i < 1000; i++) {
await RNFS.read(url, 16777216, 0, 'base64').then((data) => { // 16777216 - 16MB chunk, 0 - start seek
console.log('Read file', i)
}).catch(err => console.log(err))
}
}
Video report: https://www.dropbox.com/s/3lzcrtzst0dnomw/Screen%20Recording%202019-10-18%20at%2010.49.43.mov?dl=0
If I use a function without 'async', then the function recursively calls itself and the application crash
Example test code:
onReadAssets = () => {
const url = ${node.asset.url}
// <—— Large file
for (let i = 0; i < 1000; i++) {
RNFS.read(url, 16777216, 0, 'base64').then((data) => { // 16777216 - 16MB chunk, 0 - start seek
console.log('Read file', i)
}).catch(err => console.log(err))
}
}
Video report: https://www.dropbox.com/s/aq3y9dfeqo4mo7o/Screen%20Recording%202019-10-18%20at%2010.52.40.mov?dl=0
I found a similar problem in : https://github.com/itinance/react-native-fs/issues/746
Thanks.
I'm currently struggling with the same issue. Using the RNFS.read()
method in a loop doesn't release the memory for some reason. There's a linear growth in memory usage with each read/uploaded file chunk.
any update on this issue.
this is still unresolved, unfortunately.