-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ANR and Segfault during large transaction #1080
Comments
Hello, the funny thing about Services is that most times they don't run on a separate thread, and that's most likely why you see the ANRs. I would suggest using a worker thread as you can see in the examples in our repo. |
Thanks for the help! I've tried it as an Async task as well, and even an entirely separate process. To be fair, this is on a very memory-limited device, which garbage collects extremely often. Trying another process / Async task doesn't stop the garbage collection from ANR'ing the app. |
I see. So it's a matter of the GC stopping the world in order to be able to keep up. One known problem is that when iterating through RealmResults we are creating objects so fast that the GC is not able to keep up. We saw this kind of issue only internally so far, and we already have a fix for it, but it comes at a performance cost, which is the reason it has not been merged yet. Seeing the code of your transaction can help us evaluate it. |
Sure! So the user data comes in as a 4.5 MB String. I use JacksonParser to handle the converting of this huge String into JSONNodes, instead of the built-in JSONObject, because I'll frequently run into OutOfMemory Exceptions if I go the JSONObject route. In a for loop, I run this createOrUpdate function 8k times.
|
Also, here's the stacktrace from ANR. 05-05 04:40:07.771 26684-26684/com.ekocustom.true A/libc﹕ Fatal signal 6 (SIGABRT) at 0x000001d4 (code=0), thread 26684 (.ekocustom.true) |
Parsing a 4.5 MB JSON file might be too large for most Android devices: http://stackoverflow.com/questions/9205821/android-parsing-5mb-json-file-causing-out-of-memory-exception |
I assume your question was answered. Please reopen if that was not the case. |
I am having the same issue while i am trying to modify DB with 13K records. It blocks the UI. *Using JobManager for Background operation |
@A86S do you insert the elements within the list in one transaction? Can you replace |
@Zhuinden yes i am trying insert/update the list in one transaction. i have changed the code with insertOrUpdate() but still freeze UI with 7k records. |
....are you sure you're executing this on a background thread? |
@Zhuinden Yes i am sure i have tested it with both AsyncTask and JobManager. |
You should probably consider streaming the JSON and using only 1 element at a time instead of obtaining every element in a list It's a bit of a mess but it can reduce your 7000 objects to 1 |
Hey, keep it up Realm team! Awesome work.
I've got 8k update operations running in the same transaction in a background service, which leads to ANRs and a Segfault. I broke up it up into 200 operation chunks, which doesn't ANR/crash, but this seems like a bandaid fix. Any advice for how to handle this?
The text was updated successfully, but these errors were encountered: