Android RoomDatabase Cruash "Cursor window allocation of 4194304 bytes failed" - android

I got two crush on firebase
1.Caused by android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed.
2.Caused by android.database.CursorWindowAllocationException: Could not allocate CursorWindow '/data/user/0/com.myname.de/databases/bm_634255623.db' of size 2097152 due to error -12.
i know cursor leak,but i use jetpack room, i can't get cursor
room version:
def room_version = "2.2.5"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
please help me,thanks
why happen this crush?

This issue could happen because of memory allocation for Cursor. The idea is that the CursorWindows has maximum 2mb so for that query in order to get some consistent data.
#Dao
interface UserDao {
#Transaction
#Query("SELECT * FROM user")
fun getAll(): List<User>
}
You should annotate your DAO methods with #Transaction to get rid of this error.

Related

How to FIX OutOfMemoryError for seemingly very light resource 64 byte

I have got a android.view.InflateException, and further down the stacktrace, I've got this outOfMemory exception at the line where a 4 kb XML drawable is loaded with srcCombat into an AppCompatImageView.
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/img_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_menu_profile_arrow" />
StackTrace::
Caused by java.lang.OutOfMemoryError: Failed to allocate a 64 byte allocation with 3187176 free bytes and 3112KB until OOM, target footprint 402653184, growth limit 402653184; giving up on allocation because <1% of heap free after GC.
at android.graphics.drawable.VectorDrawable.inflateChildElements(VectorDrawable.java:853)
at android.graphics.drawable.VectorDrawable.inflate(VectorDrawable.java:752)
Whats the meaning of this, I mean, if there is 3187176 free bytes why can't a 64 byte be allocated?
Whats the meaning of OOM, target footprint, and growth limit.

Google Text Recognition Error Android Studio

I am developing an app in which I am implementing google text recognition.
This is the link that I am following :
https://developers.google.com/ml-kit/vision/text-recognition/android
I have done everything described there but still I am getting error.
This is what I have in my gradle file:
implementation 'com.google.android.gms:play-services-mlkit-text-recognition:16.1.0'
I have these lines too in my manifest file:
<uses-permission android:name="android.permission.INTERNET"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
<meta-data
android:name="com.google.mlkit.vision.DEPENDENCIES"
android:value="ocr" />
I am performing a click on a button OCR and then I am calling below lines of code:
InputImage inputImage = InputImage.fromBitmap(bitmap, 0);
TextRecognition.getClient().process(inputImage).addOnSuccessListener(new OnSuccessListener<Text>() {
#Override
public void onSuccess(Text text) {
string = text.getText();
success = true;
}
}).addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
e.printStackTrace();
success = false;
}
});
Error is thrown as soon as I Click on OCR button.
Following is the stack trace:
W/DynamiteModule: Local module descriptor class for com.google.android.gms.vision.dynamite.ocr not found.
E/LibraryVersion: Failed to get app version for libraryName: text-recognition
I/DynamiteModule: Considering local module com.google.android.gms.vision.dynamite.ocr:0 and remote module com.google.android.gms.vision.dynamite.ocr:0
D/TextNativeHandle: Cannot load feature, fall back to load dynamite module.
W/scanner.camsca: Unsupported class loader
W/scanner.camsca: Skipping duplicate class check due to unsupported classloader
I/DynamiteModule: Considering local module com.google.android.gms.vision.ocr:0 and remote module com.google.android.gms.vision.ocr:1
Selected remote version of com.google.android.gms.vision.ocr, version >= 1
V/DynamiteModule: Dynamite loader version >= 2, using loadModule2NoCrashUtils
I/DynamiteLoaderV2: [71] VisionOcr.optional
W/scanner.camsca: Unsupported class loader
I/native: start_ocr_856638336_langid.cc:33 StartOcr with label: latin_script_gmvapi_android
jni_helper.cc:115 Loading model config /data/user/0/com.scanner.camscan/cache/vision/ocr/data/models/semanticlift_rpn_lstm_engine_tfmini.bincfg
I/native: region_proposal_text_detector.cc:1976 Compute manager Max in flight region detector: 1
common_util.h:39 Removing Thread Pool: ocr_region
tensor_detector_client.cc:1643 Compute manager Max in flight detector: 1
I/native: common_util.h:35 Resizing Thread Pool: ocr_det to 4
I/native: tfmini_model_interface.cc:124 Loaded weights from /data/user/0/com.scanner.camscan/cache/vision/ocr/data/models/tfmini_rpn_detector_space_to_depth_gray_quantized_v2_model.data
timer.cc:71 PhotoOcrEngine::Init (detector): 3.72583 ms (elapsed)
assist_recognizer.cc:94 Initializing nugget matcher with /data/user/0/com.scanner.camscan/cache/vision/ocr/data/models/nugget_stats_1.0.dat
I/native: timer.cc:71 PhotoOcrEngine::Init (assist recognizer): 0.262136 ms (elapsed)
I/native: timer.cc:71 LanguageIdMutator: 4.42141 ms (elapsed)
timer.cc:71 BeamSearch::Init (mutator): 4.58203 ms (elapsed)
I/native: common_util.h:35 Resizing Thread Pool: ocr_segm to 4
I/native: tfmini_model_interface.cc:102 Loaded fp16 weights from /data/user/0/com.scanner.camscan/cache/vision/ocr/data/models/tfmini_latin_conv_model.data_fp16
I/native: tfmini_model_interface.cc:102 Loaded fp16 weights from /data/user/0/com.scanner.camscan/cache/vision/ocr/data/models/tfmini_latin_lstm_model.data_fp16
timer.cc:71 PhotoOcrEngine::Init (recognizer): 8.83693 ms (elapsed)
timer.cc:71 Init: 13.0749 ms (elapsed)
I/native: start_ocr_856638336_langid.cc:42 StartOcr success
How can I rectify this error.
Thank you
I have faced a similar problem before.
These are not actual errors. They are just warnings and messages. You can ignore them.
What I guess is, you are putting true in the boolean variable success on onSuccess and false on onFailure and performing further actions based on its value.
Just directly call further methods from onSuccess after string = text.getText();

RxJava blockingFirst/Single returns wrong exception in JUnit 5 Retrofit Test

Test below is expected to return HttpException but it returns RuntimeException instead.
#Test
fun `Server down returns 500 error`() {
mockWebServer.enqueue(MockResponse().setResponseCode(500))
val exception: Exception =
assertThrows(
HttpException::class.java
) {
githubApi
.getRepoList("test")
.blockingFirst()
}
assertEquals(exception, HttpException::class)
}
Log for failed test is
INFO: MockWebServer[54339] received request: GET /users/test/repos
HTTP/1.1 and responded: HTTP/1.1 500 Server Error Feb 07, 2020 9:20:11
PM okhttp3.mockwebserver.MockWebServer acceptConnections INFO:
MockWebServer[54339] done accepting connections: Socket closed Feb 07,
2020 9:20:11 PM
okhttp3.mockwebserver.MockWebServer$serveConnection$$inlined$execute$1
runOnce INFO: MockWebServer[54339] connection from /127.0.0.1 failed:
java.net.SocketException: Socket closed
org.opentest4j.AssertionFailedError: Unexpected exception type thrown
==> expected: com.jakewharton.retrofit2.adapter.rxjava2.HttpException but was:
java.lang.RuntimeException
As #akarnokd suggests you need to extract the cause.
assertEquals(exception.cause, HttpException::class)
alternatively you can also test this without blockingFirst like this:
githubApi
.getRepoList("test")
.test()
.assertError(HttpException::class)

FATAL EXCEPTION: FrescoDecodeExecutor-2

I got the crash FATAL EXCEPTION: FrescoDecodeExecutor-2
Throwing OutOfMemoryError "Failed to allocate a 64256268 byte allocation with 16777216 free bytes and 49MB until OOM"
StackTrace :
java.lang.OutOfMemoryError: Failed to allocate a 64256268 byte allocation with 16777216 free bytes and 49MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:905)
at android.graphics.Bitmap.createBitmap(Bitmap.java:882)
at android.graphics.Bitmap.createBitmap(Bitmap.java:849)
at com.facebook.imagepipeline.memory.BitmapPool.alloc(BitmapPool.java:51)
at com.facebook.imagepipeline.memory.BitmapPool.alloc(BitmapPool.java:26)
at com.facebook.imagepipeline.memory.BasePool.get(BasePool.java:255)
at com.facebook.imagepipeline.platform.ArtDecoder.decodeStaticImageFromStream(ArtDecoder.java:147)
at com.facebook.imagepipeline.platform.ArtDecoder.decodeJPEGFromEncodedImage(ArtDecoder.java:127)
at com.facebook.imagepipeline.decoder.DefaultImageDecoder.decodeJpeg(DefaultImageDecoder.java:173)
at com.facebook.imagepipeline.decoder.DefaultImageDecoder$1.decode(DefaultImageDecoder.java:56)
at com.facebook.imagepipeline.decoder.DefaultImageDecoder.decode(DefaultImageDecoder.java:119)
at com.facebook.imagepipeline.producers.DecodeProducer$ProgressiveDecoder.doDecode(DecodeProducer.java:254)
at com.facebook.imagepipeline.producers.DecodeProducer$ProgressiveDecoder.access$300(DecodeProducer.java:113)
at com.facebook.imagepipeline.producers.DecodeProducer$ProgressiveDecoder$1.run(DecodeProducer.java:152)
at com.facebook.imagepipeline.producers.JobScheduler.doJob(JobScheduler.java:202)
at com.facebook.imagepipeline.producers.JobScheduler.access$000(JobScheduler.java:22)
at com.facebook.imagepipeline.producers.JobScheduler$1.run(JobScheduler.java:73)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at com.facebook.imagepipeline.core.PriorityThreadFactory$1.run(PriorityThreadFactory.java:51)
at java.lang.Thread.run(Thread.java:761)
Image is 5,34 Mo big 5344x3006 and was shoot by the phone Motorola XT1562, Android 7.1.1
implementation 'com.facebook.fresco:fresco:1.9.0'
Of course it does not reproduced every time the app is running
What's wrong ? Help ! :-)

during the download i get E/CursorWindow

my application is downloading large files from internet. but during the download i get
E/CursorWindow﹕ Could not create CursorWindow from Parcel due to error -12.
error. I am using download manager.
I get a very long out put part it looks like:
Cursor finalized without prior close()
Cursor finalized without prior close()
Cursor finalized without prior close()
Cursor finalized without prior close()
Cursor finalized without prior close()
Cursor finalized without prior close()
Cursor finalized without prior close()
E/CursorWindow﹕ Could not create CursorWindow from Parcel due to error -12.
E/CursorWindow﹕ Could not create CursorWindow from Parcel due to error -12.
E/CursorWindow﹕ Could not create CursorWindow from Parcel due to error -12.
E/CursorWindow﹕ Could not create CursorWindow from Parcel due to error -12.
E/CursorWindow﹕ Could not create CursorWindow from Parcel due to error -12.
E/CursorWindow﹕ Could not create CursorWindow from Parcel due to error -12.
09-01 23:08:44.241 17397-17615/com.yasna.appsaraai W/System.err﹕ at java.lang.Thread.run(Thread.java:841)
09-01 23:08:44.246 16969-17654/? E/CursorWindow﹕ Could not allocate CursorWindow '/data/data/com.android.providers.downloads/databases/downloads.db' of size 2097152 due to error -12.
09-01 23:08:44.246 16969-17654/? E/JavaBinder﹕ *** Uncaught remote exception! (Exceptions are not yet supported across processes.)
android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. # Open Cursors=552 (# cursors opened by this proc=4) (# cursors opened by pid 17397=548)
at android.database.CursorWindow.<init>(CursorWindow.java:109)
at android.database.CursorWindow.<init>(CursorWindow.java:100)
at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:198)
at android.database.sqlite.SQLiteCursor.clearOrCreateWindow(SQLiteCursor.java:301)
at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:139)
at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:133)
at android.database.CursorToBulkCursorAdaptor.getBulkCursorDescriptor(CursorToBulkCursorAdaptor.java:148)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:118)
at android.os.Binder.execTransact(Binder.java:404)
at dalvik.system.NativeStart.run(Native Method)
09-01 23:08:44.251 17397-17615/com.yasna.appsaraai W/System.err﹕ java.lang.NullPointerException
09-01 23:08:44.251 17397-17615/com.yasna.appsaraai W/System.err﹕ at af.yasna.appsaraai.ApkFileDownloader$1.run(ApkFileDownloader.java:105)
09-01 23:08:44.251 17397-17615/com.yasna.appsaraai W/System.err﹕ at java.lang.Thread.run(Thread.java:841)
09-01 23:08:44.256 16969-17642/? E/CursorWindow﹕ Could not allocate CursorWindow '/data/data/com.android.providers.downloads/databases/downloads.db' of size 2097152 due to error -12.
09-01 23:08:44.256 16969-17642/? E/JavaBinder﹕ *** Uncaught remote exception! (Exceptions are not yet supported across processes.)
android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. # Open Cursors=552 (# cursors opened by this proc=4) (# cursors opened by pid 17397=548)
at android.database.CursorWindow.<init>(CursorWindow.java:109)
at android.database.CursorWindow.<init>(CursorWindow.java:100)
at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:198)
at android.database.sqlite.SQLiteCursor.clearOrCreateWindow(SQLiteCursor.java:301)
at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:139)
at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:133)
at android.database.CursorToBulkCursorAdaptor.getBulkCursorDescriptor(CursorToBulkCursorAdaptor.java:148)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:118)
at android.os.Binder.execTransact(Binder.java:404)
at dalvik.system.NativeStart.run(Native Method)

Categories

Resources