Ask Your Question
0

OpenCV for Android Out of memory Error

asked 2016-03-15 12:17:30 -0600

ajitabh gravatar image

03-15 22:32:18.492 7160-9350/xx.xx.xx I/dalvikvm-heap: Forcing collection of SoftReferences for 21003360-byte allocation 03-15 22:32:18.532 7160-9350/xx.xx.xx E/dalvikvm-heap: Out of memory on a 21003360-byte allocation. 03-15 22:32:18.532 7160-9350/xx.xx.xx I/dalvikvm: "AsyncTask #2" prio=5 tid=17 RUNNABLE 03-15 22:32:18.532 7160-9350/xx.xx.xx I/dalvikvm: | group="main" sCount=0 dsCount=0 obj=0x41a2c190 self=0x6116b150 03-15 22:32:18.532 7160-9350/xx.xx.xx I/dalvikvm: | sysTid=9350 nice=10 sched=0/0 cgrp=apps/bg_non_interactive handle=1628738832 03-15 22:32:18.532 7160-9350/xx.xx.xx I/dalvikvm: | state=R schedstat=( 510200159 389795835 636 ) utm=46 stm=5 core=0 03-15 22:32:18.532 7160-9350/xx.xx.xx I/dalvikvm: at android.graphics.Bitmap.nativeCreate(Native Method) 03-15 22:32:18.532 7160-9350/xx.xx.xx I/dalvikvm: at android.graphics.Bitmap.createBitmap(Bitmap.java:810) 03-15 22:32:18.532 7160-9350/xx.xx.xx I/dalvikvm: at android.graphics.Bitmap.createBitmap(Bitmap.java:787) 03-15 22:32:18.532 7160-9350/xx.xx.xx I/dalvikvm: at android.graphics.Bitmap.createBitmap(Bitmap.java:754) 03-15 22:32:18.532 7160-9350/xx.xx.xx I/dalvikvm: at com.scanlibrary.ScanActivity.getScannedBitmap(Native Method) 03-15 22:32:18.532 7160-9350/xx.xx.xx I/dalvikvm: at com.scanlibrary.ScanFragment.getScannedBitmap(ScanFragment.java:196) 03-15 22:32:18.532 7160-9350/xx.xx.xx I/dalvikvm: at com.scanlibrary.ScanFragment.access$700(ScanFragment.java:32) 03-15 22:32:18.532 7160-9350/xx.xx.xx I/dalvikvm: at com.scanlibrary.ScanFragment$ScanAsyncTask.doInBackground(ScanFragment.java:216) 03-15 22:32:18.532 7160-9350/xx.xx.xx I/dalvikvm: at com.scanlibrary.ScanFragment$ScanAsyncTask.doInBackground(ScanFragment.java:200) 03-15 22:32:18.532 7160-9350/xx.xx.xx I/dalvikvm: at android.os.AsyncTask$2.call(AsyncTask.java:288) 03-15 22:32:18.532 7160-9350/xx.xx.xx I/dalvikvm: at java.util.concurrent.FutureTask.run(FutureTask.java:237) 03-15 22:32:18.532 7160-9350/xx.xx.xx I/dalvikvm: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 03-15 22:32:18.532 7160-9350/xx.xx.xx I/dalvikvm: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 03-15 22:32:18.532 7160-9350/xx.xx.xx I/dalvikvm: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 03-15 22:32:18.532 7160-9350/xx.xx.xx I/dalvikvm: at java.lang.Thread.run(Thread.java:841) 03-15 22:32:18.532 7160-9350/xx.xx.xx E/cv::error(): OpenCV Error: Assertion failed (8) in H, file , line 175 03-15 22:32:18.532 7160-9350/xx.xx.xx W/dalvikvm: Exception thrown (Ljava/lang/OutOfMemoryError;) while throwing internal exception (Ljava/lang/Exception;) 03-15 22:32:18.542 7160-9350/xx.xx.xx W/dalvikvm: threadid=17: thread exiting with uncaught exception (group=0x415d5ce0) 03-15 22:32:18.542 7160-9350/xx.xx.xx E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #2 Process: xx.xx.xx, PID: 7160 ... (more)

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-03-16 03:34:38 -0600

berak gravatar image

updated 2016-03-16 03:35:40 -0600

the java gc does not see any native c++ memory allocation, so you can't rely on that.

if you do e.g. something like this:

Mat src = ...
Mat dst = new Mat();
Imgproc.cvtColor(src,dst, COLOR_BGR2RGB);

then you have to release anything you allocated using new manually:

dst.release();
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-03-15 12:17:30 -0600

Seen: 1,103 times

Last updated: Mar 15 '16