Android Question OutOfMemory error under Android 2.3.x

peacemaker

Expert
Licensed User
Longtime User
I found that under Android 2.3 an app (using SQLite with blobs for bitmaps) - has OutOfMemory error soon after start, and even before using activity that works with bitmaps.

Under Android 4.0, or 4.2 with the same 512 MB RAM - no such issue at all.
Compiled by b4a v.3.0
"Downsampling image due to lack of memory." occured more and more often. But no bitmaps were operated !

Erel, maybe this log has any to understand ?


B4X:
LogCat connected to: 80A354043043692369
--------- beginning of /dev/log/system


--------- beginning of /dev/log/main


<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (main) Create, isFirst = true **


<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (main) Resume **
<!>anywheresoftware.b4a.BA 480<!> DropTable: DROP TABLE IF EXISTS [ways]
<!>anywheresoftware.b4a.BA 480<!> CreateTable: CREATE TABLE IF NOT EXISTS [ways] ([id] INTEGER PRIMARY KEY AUTOINCREMENT, [way] TEXT, [input] TEXT, [output] TEXT)
<!>anywheresoftware.b4a.BA 480<!> InsertMaps (first query out of 10): INSERT INTO [ways] ([id], [way], [input], [output]) VALUES (?, ?, ?, ?)
<!>anywheresoftware.b4a.BA 480<!> CreateTable: CREATE TABLE IF NOT EXISTS [parts] ([id] INTEGER PRIMARY KEY AUTOINCREMENT, [name] TEXT, [waytype] INTEGER, [way] INTEGER, [desc] TEXT, [link] TEXT, [filename] TEXT, [file] BLOB, [picture] BLOB, [priority] TEXT, [value] TEXT)
<!>anywheresoftware.b4a.BA 480<!> CreateTable: CREATE TABLE IF NOT EXISTS [functions] ([id] INTEGER PRIMARY KEY AUTOINCREMENT, [name] TEXT, [source] INTEGER, [result] INTEGER, [desc] TEXT, [link] TEXT, [filename] TEXT, [file] BLOB, [picture] BLOB, [priority] TEXT)
<!>anywheresoftware.b4a.BA 480<!> CreateTable: CREATE TABLE IF NOT EXISTS [general] ([id] INTEGER PRIMARY KEY, [project_name] TEXT, [author] TEXT, [template] TEXT, [field1] TEXT, [field2] TEXT, [field3] TEXT)
<!>anywheresoftware.b4a.BA 480<!> InsertMaps (first query out of 3): INSERT INTO [general] ([project_name]) VALUES (?)
<!>anywheresoftware.b4a.BA 480<!> DB inited !
<!>anywheresoftware.b4a.BA 480<!> CreateTable: CREATE TABLE IF NOT EXISTS [DBVersion] ([version] INTEGER PRIMARY KEY)
<!>anywheresoftware.b4a.BA 480<!> CreateTable: CREATE TABLE IF NOT EXISTS [DBVersion] ([version] INTEGER PRIMARY KEY)
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (main) Pause, UserClosed = false **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (prj) Create, isFirst = true **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (prj) Resume **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (prj) Pause, UserClosed = false **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (web) Create, isFirst = true **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (web) Resume **
<!>anywheresoftware.b4a.BA 480<!> requestCode = 1
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (web) Pause, UserClosed = false **
<!>anywheresoftware.b4a.BA 480<!> sending message to waiting queue (OnActivityResult)
<!>anywheresoftware.b4a.BA 480<!> running waiting messages (1)
<!>anywheresoftware.b4a.BA 480<!> Arrived: 1, 1
<!>anywheresoftware.b4a.BA 480<!> ~e:User canceled. (response: -1005:User cancelled)
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (web) Resume **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (web) Pause, UserClosed = true **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (prj) Resume **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (prj) Pause, UserClosed = false **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (prjmenu) Create, isFirst = true **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (prjmenu) Resume **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (prjmenu) Pause, UserClosed = false **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (results) Create, isFirst = true **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (results) Resume **
<!>anywheresoftware.b4a.BA 480<!> ExecuteMemoryTable: SELECT way FROM ways WHERE output = '1'
<!>anywheresoftware.b4a.BA 480<!> ExecuteMemoryTable: SELECT name FROM parts WHERE waytype = '1'
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (results) Pause, UserClosed = true **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (prjmenu) Resume **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (prjmenu) Pause, UserClosed = false **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (results) Create, isFirst = false **
<!>anywheresoftware.b4a.BA 480<!> ~w:1003,results,33
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (results) Resume **
<!>anywheresoftware.b4a.BA 480<!> ExecuteMemoryTable: SELECT way FROM ways WHERE input = '1'
<!>anywheresoftware.b4a.BA 480<!> ExecuteMemoryTable: SELECT name FROM parts WHERE waytype = '0'


<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (results) Pause, UserClosed = true **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (prjmenu) Resume **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (prjmenu) Pause, UserClosed = false **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (functions) Create, isFirst = true **
<!>anywheresoftware.b4a.BA 480<!> Downsampling image due to lack of memory.
<!>anywheresoftware.b4a.BA 480<!> Downsampling image due to lack of memory: 6
<!>anywheresoftware.b4a.BA 480<!> Downsampling image due to lack of memory.
<!>anywheresoftware.b4a.BA 480<!> Downsampling image due to lack of memory: 6
<!>anywheresoftware.b4a.BA 480<!> Downsampling image due to lack of memory: 12
<!>anywheresoftware.b4a.BA 480<!> Downsampling image due to lack of memory: 24
<!>anywheresoftware.b4a.BA 480<!> Downsampling image due to lack of memory.
<!>anywheresoftware.b4a.BA 480<!> Downsampling image due to lack of memory: 2
<!>anywheresoftware.b4a.BA 480<!> Downsampling image due to lack of memory: 4
<!>anywheresoftware.b4a.BA 480<!> Downsampling image due to lack of memory.
<!>anywheresoftware.b4a.BA 480<!> Downsampling image due to lack of memory: 2
<!>anywheresoftware.b4a.BA 480<!> Downsampling image due to lack of memory: 4
<!>anywheresoftware.b4a.BA 480<!> Downsampling image due to lack of memory: 8
<!>anywheresoftware.b4a.BA 480<!> Downsampling image due to lack of memory: 16
<!>anywheresoftware.b4a.BA 480<!> Downsampling image due to lack of memory.
<!>anywheresoftware.b4a.BA 480<!> Downsampling image due to lack of memory: 6
<!>anywheresoftware.b4a.BA 480<!> Downsampling image due to lack of memory: 12
<!>anywheresoftware.b4a.BA 480<!> Downsampling image due to lack of memory: 24
<!>anywheresoftware.b4a.BA 480<!> Downsampling image due to lack of memory: 48
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (functions) Resume **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (functions) Pause, UserClosed = true **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (prjmenu) Resume **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (prjmenu) Pause, UserClosed = false **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (results) Create, isFirst = false **
<!>anywheresoftware.b4a.BA 480<!> Downsampling image due to lack of memory.
<!>anywheresoftware.b4a.BA 480<!> ~w:1003,results,33
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (results) Resume **
<!>anywheresoftware.b4a.BA 480<!> ExecuteMemoryTable: SELECT way FROM ways WHERE input = '1'
<!>anywheresoftware.b4a.BA 480<!> ExecuteMemoryTable: SELECT name FROM parts WHERE waytype = '0'
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (results) Pause, UserClosed = true **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (prjmenu) Resume **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (prjmenu) Pause, UserClosed = false **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (results) Create, isFirst = false **
<!>anywheresoftware.b4a.BA 480<!> Downsampling image due to lack of memory.
<!>anywheresoftware.b4a.BA 480<!> ~w:1003,results,33
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (results) Resume **
<!>anywheresoftware.b4a.BA 480<!> ExecuteMemoryTable: SELECT way FROM ways WHERE output = '1'
<!>anywheresoftware.b4a.BA 480<!> ExecuteMemoryTable: SELECT name FROM parts WHERE waytype = '1'
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (results) Pause, UserClosed = true **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (prjmenu) Resume **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (prjmenu) Pause, UserClosed = true **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (prj) Resume **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (prj) Pause, UserClosed = false **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (prjmenu) Create, isFirst = false **
<!>anywheresoftware.b4a.BA 480<!> Downsampling image due to lack of memory.
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (prjmenu) Resume **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (prjmenu) Pause, UserClosed = false **


<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (functions) Create, isFirst = false **
<!>anywheresoftware.b4a.BA 480<!> Downsampling image due to lack of memory.
<!>anywheresoftware.b4a.BA 480<!> Downsampling image due to lack of memory.
<!>anywheresoftware.b4a.BA 480<!> ~w:1003,functions,31
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (functions) Resume **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (functions) Pause, UserClosed = true **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (prjmenu) Resume **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (prjmenu) Pause, UserClosed = false **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (details) Create, isFirst = true **
<!>anywheresoftware.b4a.BA 480<!> Downsampling image due to lack of memory.
<!>anywheresoftware.b4a.BA 480<!> Downsampling image due to lack of memory.
<!>anywheresoftware.b4a.BA 480<!> Downsampling image due to lack of memory.
<!>anywheresoftware.b4a.BA 480<!> Downsampling image due to lack of memory.
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (details) Resume **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (details) Pause, UserClosed = true **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (prjmenu) Resume **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (prjmenu) Pause, UserClosed = true **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (prj) Resume **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (prj) Pause, UserClosed = false **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (web) Create, isFirst = false **
<!>anywheresoftware.b4a.BA 480<!> ~i:** Activity (web) Resume **
<!>anywheresoftware.b4a.BA 480<!> android.view.InflateException: Binary XML file line #21: Error inflating class android.widget.ZoomControls
    at android.view.LayoutInflater.createView(LayoutInflater.java:518)
    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:383)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
    at android.widget.ZoomButtonsController.createContainer(ZoomButtonsController.java:262)
    at android.widget.ZoomButtonsController.<init>(ZoomButtonsController.java:211)
    at android.webkit.WebView.getZoomButtonsController(WebView.java:6219)
    at android.webkit.WebView.startDrag(WebView.java:5608)
    at android.webkit.WebView.onTouchEvent(WebView.java:5346)
    at android.view.View.dispatchTouchEvent(View.java:3885)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:903)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1703)
    at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1133)
    at android.app.Activity.dispatchTouchEvent(Activity.java:2096)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1687)
    at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2196)
    at android.view.ViewRoot.handleMessage(ViewRoot.java:1880)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:3729)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:632)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.constructNative(Native Method)


    at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
    at android.view.LayoutInflater.createView(LayoutInflater.java:505)
    ... 31 more
Caused by: android.view.InflateException: Binary XML file line #21: Error inflating class android.widget.ZoomButton
    at android.view.LayoutInflater.createView(LayoutInflater.java:518)
    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:383)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
    at android.widget.ZoomControls.<init>(ZoomControls.java:49)
    ... 34 more
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.constructNative(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
    at android.view.LayoutInflater.createView(LayoutInflater.java:505)
    ... 40 more
Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
    at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460)
    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
    at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
    at android.content.res.Resources.loadDrawable(Resources.java:1709)
    at android.content.res.Resources.getDrawable(Resources.java:581)
    at android.graphics.drawable.StateListDrawable.
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
Right ! 5 kb picture .png is used as background often. If to save it to BMP truecolor = 1 MB.
But activities are open and close one by one. Should be.
Even if to load 3-5 times this file - why such problem under Android 2.3 ?
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Yes, thanks, Erel - removing this picture helped to avoid this error at all under Android 2.3.

How did you test that? With different devices? With the emulator?

3 real devices.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Yes, thanks, Erel - removing this picture helped to avoid this error at all under Android 2.3.



3 real devices.
Each device has a different max. VM heap size. The total RAM means nothing. All Java programs are run in a virtual memory space which is limited to an amount between 16 and 64 MB for most devices. So if your devices with ICS and JellyBean (probably more recent than your device under Gingerbread) have a max. VM heap size of 48 Mb and your program requires 40 MB, no problem. If the device under Gingerbread is limited to 32 MB -> out of memory.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Yes, old device. But strange that 5 KB PNG (~1 MB as BMP), if used as backgound on all activities (6 or 7) - gives such trouble.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Yes, old device. But strange that 5 KB PNG (~1 MB as BMP), if used as backgound on all activities (6 or 7) - gives such trouble.
The file size does not matter, only the image dimensions. You can compute the used memory with this simple formula: width * height * 4. If the device is old, then it has only 16 MB to hold the code of your app and all data. It's very easy to see an OoM on these devices with a few bitmaps.
 
Upvote 0
Top