F
F
ftp272013-01-19 10:03:41
Java
ftp27, 2013-01-19 10:03:41

RAM limit in Android apps?

There is a task to display many custom lists with images sized 400x200 (there are about 500 such images), respectively, to adequately display all these lists, you need to load all these images into memory. There were also large images, but, nevertheless, it was decided to load them from SD media, which cannot be done with list items. Otherwise, this loading becomes very noticeable. Maybe I'm doing something wrong, which is most likely, but the problem has risen by itself. When opening a lot of points, the application crashes with the following log:

01-19 10:47:53.554: D/dalvikvm(4992): GC_BEFORE_OOM freed <1K, 11% free 57601K/64519K, paused 32ms
01-19 10:47:53.554: E/dalvikvm-heap(4992): Out of memory on a 5808016-byte allocation.
01-19 10:47:53.554: I/dalvikvm(4992): "AsyncTask #4" prio=5 tid=14 RUNNABLE
01-19 10:47:53.554: I/dalvikvm(4992): | group="main" sCount=0 dsCount=0 obj=0x419a07e0 self=0x1ef45f0
01-19 10:47:53.554: I/dalvikvm(4992): | sysTid=5009 nice=10 sched=0/0 cgrp=bg_non_interactive handle=32172032
01-19 10:47:53.554: I/dalvikvm(4992): | schedstat=( 3002593976 773101830 3985 ) utm=284 stm=15 core=1
01-19 10:47:53.554: I/dalvikvm(4992): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
01-19 10:47:53.554: I/dalvikvm(4992): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:582)
01-19 10:47:53.554: I/dalvikvm(4992): at android. graphics.BitmapFactory.decodeStream(BitmapFactory.java:638)
01-19 10:47:53.554: I/dalvikvm(4992): at ftp27.apps.cImageManager.downloadImage(cImageManager.java:199)
01-19 10:47: 53.554: I/dalvikvm(4992): at ftp27.apps.cImageManager.access$2(cImageManager.java:179)
01-19 10:47:53.554: I/dalvikvm(4992): at ftp27.apps.cImageManager$3.doInBackground (cImageManager.java:223)
01-19 10:47:53.554: I/dalvikvm(4992): at ftp27.apps.cImageManager$3.doInBackground(cImageManager.java:1)
01-19 10:47:53.554: I/ dalvikvm(4992): at android.os.AsyncTask$2.call(AsyncTask.java:264)
01-19 10:47:53.554: I/dalvikvm(4992): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
01-19 10:47:53.554: I/dalvikvm(4992) : at java.util.concurrent.FutureTask.run(FutureTask.java:137)
01-19 10:47:53.554: I/dalvikvm(4992): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java: 208)
01-19 10:47:53.554: I/dalvikvm(4992): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
01-19 10:47:53.554: I/dalvikvm(4992) : at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
01-19 10:47:53.554: I/dalvikvm(4992): at java.lang.Thread.run(Thread.java:856 )
01-19 10:47:53.554: D/skia(4992): - decoder->decode returned false
01-19 10:47:53.562: W/dalvikvm(4992): threadid=12: thread exiting with uncaught exception (group=0x40c031f8)
01-19 10:47:53.570: I/Process(4992): Sending signal. PID: 4992 SIG: 9

How to get around this limitation?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mihaildemidoff, 2013-01-19
@ftp27

This limitation can be circumvented in three ways.
1) You can make the OS think that your application uses much less memory than it really is (unfortunately I can’t find an article with a solution right now). But this solution is the worst of the options, in short, the memory is still not infinite, it must be properly managed.
2) You can set android:largeHeap="true" in AndroidManifest.xml in application , the amount of memory allocated to the application will be increased, but this option is again suitable for the most unusual cases, for example, when you need to store one large piece of non-breakable data in memory.
developer.android.com/guide/topics/manifest/application-element.html
3) The most correct option, in my opinion, is the following: only visible images should be in memory, all other images should be unloaded from memory (by the way, do not forget to recycle on the bitmap). Images from a flash card are pulled up pretty quickly.

V
vovkab, 2013-01-20
@vovkab

There are a lot of loaders who do everything themselves, and they will save as much as they need on the card and in memory, you just need to pass it the url of the desired image:
1. an example from Google:
developer.android.com/training/displaying-bitmaps/index .html
developer.android.com/shareables/training/BitmapFun.zip
2. Universal-Image-Loader
github.com/nostra13/Android-Universal-Image-Loader
3. and another one:
wuman.github.com/AndroidImageLoader/
On in fact, there are a lot of different ones, so choose for every taste and color.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question