Low level android out of memory crashes using Realm - android

I've been getting many OOM crashes in my android app (many but not all of them seem to be in Realm code:
First:
io.realm.exceptions.RealmError: Unrecoverable error. mmap() failed: Out of memory size: 872415232 offset: 0 in /Users/zaki/fromgit/realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 92
Second:
io.realm.exceptions.RealmError: Unrecoverable error. Too many open files in /Users/zaki/fromgit/realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 92
but also some even more vague memory issues:
java.lang.OutOfMemoryError: Could not allocate JNI Env
These issues seem to only happen in production and watching the memory usage in my app seems to hover pretty consistently around 10MB.

Related

Error while running espresso test cases more than 150 case failed with an error (Out Of Memory)

When we have more than 150–200 automation test cases written for our application which takes around 1 to 1.5 hours to run completely. There we can face an issue of OOM (Out Of Memory) error while running test cases.
Tried solution methods :
Increasing the RAM size
Android Test Orchestrator
JacocoTestReport
**Increasing the RAM size : **
Increased the RAM size heap memory size in android studio but still it showing the out of memory exception while running the test case.
enter image description here
**
Android Test Orchestrator : **
Implemented the orchestrator test case method. all test cases are running but all test cases are failing.
Reference Link : https://medium.com/globant/oom-out-of-memory-error-while-running-espresso-test-cases-power-of-android-test-orchestrator-721ac7012f86
**JacocoTestReport : **
Implemented the Jacoco test report while running the test cases. It throwing the out of memory exception
while running the test case.
Reference Link :
https://about.codecov.io/blog/code-coverage-for-android-development-using-kotlin-jacoco-github-actions-and-codecov/
enter image description here
Need to run all the testcases Without any error.

Every runtime error reported as SIGSEGV error in android studio

I have linked some c++ codes to android studio project and it works with no problem, but every time I encounter with a runtime error in java code, android studio won't tell me the problem precisely and reports only this error in debugger:
Signal = SIGSEGV (signal SIGSEGV: invalid address (fault address: 0xc))
What is the problem?
This primarily occurs due to one of the 2 reasons :
1) Invalid memory reference.
2) Eating up too much memory.
Now, debugging this issue can be a bit intimidating.
So start finding out points where your code may be doing INVALID MEMORY ACCESS causing SIGSEGV error or points where your code is starting too many threads.
And You have to find out if this issue is regularly occuring or 1 in 5(or so) times.
Because I encountered the problem in one project and that occured 1 in 5-6 times.

SQLCipher fails with I/O error for file size over 2GB on Android

I am trying to encrypt a sqlite database that is over 2GB in size on Android. This causes the app to crash with an I/O error.
I am using the binaries for 3.1.0 available on the page at https://www.zetetic.net/sqlcipher/sqlcipher-for-android/
Is there a limit to the file size that can be used with the sqlCipher for Android.
Thanks.
[UPDATE]
The error I get is
net.sqlcipher.database.SQLiteDiskIOException: disk I/O error
with the stack trace as
[net.sqlcipher.database.SQLiteDatabase.native_setLocale(Native Method),
net.sqlcipher.database.SQLiteDatabase.setLocale(SQLiteDatabase.java:2092),
net.sqlcipher.database.SQLiteDatabase.<init>(SQLiteDatabase.java:1958),
net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:875),
net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:930),
com.puneet.android.sqlitesample.MainActivity.ConvertNormalToSQLCipheredDB(MainActivity.java:134),
com.puneet.android.sqlitesample.MainActivity.buttonEncryptionOnClick(MainActivity.java:69),
java.lang.reflect.Method.invokeNative(Native Method),
java.lang.reflect.Method.invoke(Method.java:515),
android.view.View$1.onClick(View.java:3978),
android.view.View.performClick(View.java:4654),
android.view.View$PerformClick.run(View.java:19438),
android.os.Handler.handleCallback(Handler.java:733),
android.os.Handler.dispatchMessage(Handler.java:95),
android.os.Looper.loop(Looper.java:146),
android.app.ActivityThread.main(ActivityThread.java:5602),
java.lang.reflect.Method.invokeNative(Native Method),
java.lang.reflect.Method.invoke(Method.java:515),
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283),
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099),
dalvik.system.NativeStart.main(Native Method)]
The file is 2GB in size.

ABORTING: HEAP MEMORY CORRUPTION on NDK env. (POCO Library, Sqlite3, Cocos2dx)

I'm facing 'ABORTING: HEAP MEMORY CORRUPTION' problem on Android NDK environment.
If I backtrace with ndk-gdb, it is mainly occurring on malloc/dlfree functions in libc.so
and after long hours of tracing the problem, it mostly happens inside sqlite3_xxx function calls, which absolutely working fine on iOS env.
I just can't find where I have to go deep.
Have anyone encountered similar problem and fixed?
I have seen memory problems, but not 'ABORTING: HEAP MEMORY CORRUPTION' that you report.
You have to find out which heap is corrupt: the Java one or the C/C++ one. Or it maybe your sql. If the log is not informative, you may try to locate the error message in the binaries.
If it is the C/C++ heap, what worked for me was replacing the standard malloc/calloc/free with my own versions.
#define malloc(x) myMalloc(x, __FILE__,__LINE__,__func__)
and so on; myMalloc() and friends print debug information so that you can find out where memory was allocated and freed. I had the source of the library and could compile it. Then logging, logging, logging...
#include <android/log.h>
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG , "~~~~~~", __VA_ARGS__)
#define DLOG(...) __android_log_print(ANDROID_LOG_DEBUG , "~~~~~~", __VA_ARGS__)
I also made myMalloc() zero the allocated memory -- just in case. One more trick is to allocate a larger chuck and put a guard value in the end of it. If that value gets corrupt -- you see.
If it is the Java heap, you will have to log your native function calls (I myself have never seen problems in the Java heap, usually Java complains about its JNI-specific stuff).
For my program, 'ABORTING: HEAP MEMORY CORRUPTION' shows when there are thread safety issues. Specifically with Cocos2d-x framework, its getFileData() function of ZipUtils may crash when loading .plist atlas and addImageAsync() at the same time on Android. Though the codes works fine on iOS.

Dalvik format failed: Failed to convert dex. PermGen space- Android

i need to use a classifier J48 in android. But running into heapspace problems. Is there a way to fix the same? I get an error that states. Dalvik format failed: Failed to convert dex. PermGen space.
So you have a memory problem using J48 in Weka on android.
I would try to diagnose this in the following order:
How much memory does your program consume? See here and here for Weka memory consumption.
Add more memory to the JVM (also in the earlier links).
Try running this on a more affluent JVM - can this run on a desktop? Or is the problem unrelated to the OS resources?
Tune your algorithm - build a smaller tree or prune it more heavily.
Prune your dataset - remove unnecessary attributes.
Prune your dataset - use fewer instances.
Use a different algorithm.
If all else fails - implement your decision tree using a different library (scipy/Orange/KNIME/Rapid miner), or roll your own.

Categories

Resources