Seeing outofmemory errors on ios in asyncstorage code
See original GitHub issueHi, using react-native-persist 5.10.0 and react-native 0.59.9, I am seeing several crashes lately in our production app like:
Error · Out of memory
[native code]stringify
node_modules/redux-persist/lib/createPersistoid.js:90:57writeStagedState
node_modules/redux-persist/lib/createPersistoid.js:78:6processNextKey
node_modules/react-native/Libraries/Core/Timers/JSTimers.js:152:6_callTimer
node_modules/react-native/Libraries/Core/Timers/JSTimers.js:414:17callTimers
node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:366:47value
node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:106:26
node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:314:8value
node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:105:17value
Could this be due to trying to store too much data in AsyncStorage? I am thinking of trying out https://github.com/bhanuc/react-native-fs-store at the RN level to drop-in this replacement for AsyncStorage … do you know if redux-persist would work with it?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:8
- Comments:23
Top Results From Across the Web
IOS (React-native) app crashes in … | Apple Developer Forums
My ReactNative app crashes in TestFlight but seems to work fine in the simulator. In the device log of the simulator, I see...
Read more >iOS: Error When accessing Async Storage: "No such file or ...
The simulator stores the data on the actual file system. I'm just guessing here, but maybe the pointer to the directory has become...
Read more >Fixing the bugs: Running out of memory - Hacking with Swift
The first problem is easily fixed: just delete the viewControllers array and any code that uses it, because it's just not needed. The...
Read more >Java OutOfMemoryError Exceptions: Causes & Fixes [Tutorial]
How to fix it: If your array is larger than your heap size, you can try increasing the heap size. If you are...
Read more >react-native run-android command errors with java.lang ...
Related Query · Cause of a OutOfMemoryError with React native Android · React Native run error: “Failed to build iOS project. · Is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m still chasing this … I updated everything to RN 0.61 (because aysnc storage was updated) and the symptoms changed (redux persist is no longer in the stack trace) but it does seem still related because I am updating state with every keystroke to a persisted reducer. My working theory is while doing this memory is consumed and not released fast enough (XCode profiling bears this out, although there does not appear to be a leak, just a surge in memory usage).
Just tried updating to redux-persist 6.0.0 and adding a throttle of 3000 to that reducer and explicitly flushing it when the state is cleared (to avoid it coming back due to throttle delay later). Testing now … it takes a while because this is not reliably reproducible.
Hope this helps; I will let you know what happens.
Same issue here. It seems like this problem happens when a device is really stressed by some large payload.
I think
JSON.stringify
used insidedefaultSerialize
function here https://github.com/rt2zz/redux-persist/blob/master/src/createPersistoid.js#L140is the cause. When the data to serialize is too big, it fails.
My current workaround is to use kind of “best effort” strategy to serialize. It will not store new data or remove the existing data, just to avoid the app from crashing.
I use redux-persist 6.0.0, Expo SDK36, AsyncStorage from react-native.
I also check the stored data when initializing screen and remove excessive data, because this error was happening when there was too much data in the store.
Since this error is quite hard to replicate, so I haven’t tested this solution in the production yet. But I will update when I found out it fixed it or not.
I hope someone will come up with better solution though. Any suggestion is helpful.