I wanted to know a little bit more about out of memory
. I know that it causes mostly on bitmaps and large objects trying to manipulate with. Anyways there is a situation where I get this error, though no images or anything else I got there, only simple textViews and the phone ram is like 12% free. So I know that there is a little amount of kb-s which my apps use as memory to allocate, but I wanted to know does that memory do anything with ram too? Can the out of memory error in android because of low RAM memory too?

- 37,241
- 25
- 195
- 267

- 1,101
- 1
- 7
- 13
-
Possible duplicate of [Strange out of memory issue while loading an image to a Bitmap object](http://stackoverflow.com/questions/477572/strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object) – Muhammad Younas Jan 18 '16 at 07:13
1 Answers
There are tons of resources in the net, just Google for it. A good point to start is http://developer.android.com/training/articles/memory.html
The RAM of the device does not directly affect your App's memory, the real problem is the so called heap. Imagine it as the small part of RAM that your App is allowed to use (there is more to it, but that should suffice for now).
All java objects are allocated, that is, saved, on the heap. The heap will always try to get rid of unused stuff if you're creating a new object, but if it can't (because you are still using all objects) it will try to grow. An OutOfMemoryError
occurs if the heap can't grow any further.
You see, it's not only bitmaps that add up to your memory consumption, but basically anything. Especially large StringBuffer
s can also be a problem.
However, Bitmaps are often the cause. If you're using e.g. an ImageView
or just setting a background image of a View, it will internally use a Bitmap.
If you're really not using any large files or Bitmaps in your App, Chance is high that you're experiencing a Memory Leak. To learn more about those (and how to discovery them) check https://corner.squareup.com/2015/05/leak-canary.html

- 9,513
- 5
- 31
- 47