How to deal with Out of Memory exception in android:
In android we encounter with out of memory exception many times. The reasons are we don't have expanding memory and completely dependent on device
the memory available on phone. So we don't have control over external factors and will need to optimize memory at our end.
Reasons of Out of memory Error ::
1.Biggest reason is memory leak i.e, Context leaking or can say Activity Leaking,a Service has the same problems as Activity in this regard.
2.You are doing process that demands continuous memory and at a point it goes beyond max memory limit of a process.
3.When you are dealing with large Bitmap and load all of them at run time.
There are some technique to optimizing the memory ::
1.Flag Techique : A solution is to set android:hardwareAccelerated=true and android:largeHeap=true
It is available after android 3.0 and so many android devices still run on gingerbread(2.3+) so it is not a reliable solution.
DVM garbage collection (Memory Leakage) : DVM Garbage collection works same as JVM garbage collection, Make sure that whenever you are done with
object and dont need it anymore, so reference as null.
3.Out of memory exception when we load image on imageview in our listview.Images come in all shapes and sizes.In many cases It might be larger than
required for a typical appication UI.
When Decode Image normally::