I am getting out of Memory error. I am working on live chat application. It is working fine but when I am running the application 1 to 2 hours on the device the heap size i
It looks like a classic memory leak. You say, that you use AsyncTask
for connection. It's very easy to leak context with an AsyncTask on configuration changes (e.g. rotation of device) when you don't know how to use it properly.
First thing - I strongly recommend you watching this: http://www.youtube.com/watch?v=_CruQY55HOk
To check if you have such a memory leak, rotate your device and check how the Garbage Collector behaves. You should have something like GC_... freed 211K, 71% free 300K/1024K, external 0K/0K, paused 1ms+1ms
in your LogCat nearly every time you rotate. Watch for changes in this part: 300K/1024K
. If you don't have memory leaks, the first part should grow and then get smaller after a few GCs. If you have a memory leak, it will grow and grow, to the point of OOM error.
If you make sure you have a memory leak this way, what you should do is to install MAT for Eclipse, learn how to use it (with the aforementioned movie) and find out what it causes.
My personal bet would be a bad implementation of AsyncTask - do you detach it from destroyed Activity and attach it to the new one? If not, start doing it (there's an excellent example by CommonsWare) or switch to AsyncTaskLoader
which does it for you and is generally a great replacement for AsyncTask
(not only for loading stuff).