question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Seeing outofmemory errors on ios in asyncstorage code

See original GitHub issue

Hi, 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:open
  • Created 4 years ago
  • Reactions:8
  • Comments:23

github_iconTop GitHub Comments

5reactions
dcherseycommented, Mar 31, 2020

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.

4reactions
foloinfocommented, Jun 4, 2020

Same issue here. It seems like this problem happens when a device is really stressed by some large payload.

I think JSON.stringify used inside defaultSerialize function here https://github.com/rt2zz/redux-persist/blob/master/src/createPersistoid.js#L140

function defaultSerialize(data) {
  return JSON.stringify(data)
}

is 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.

// try to serialize but quit if it was too much.
const serialize = (data) => {
  try{
    return JSON.stringify(data)
  }catch(err){
    captureHandledException(err) // for sentry
    return JSON.stringify({})
  }
}

const persistConfig = {
  key: 'root',
  version: 1,
  storage: AsyncStorage,
  serialize,
}

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found