I have a news app that gets its content via JSON and at times it parses very large strings. I have an object that holds all the article's data which is then saved to a database.
However, at times, I get an out of memory exception with the object class. The following is the logcat:
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.support.v4.content.ModernAsyncTask$3.done(ModernAsyncTask.java:137)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 230 byte allocation with 96 free bytes and 96B until OOM
at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:95)
at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:163)
at java.lang.StringBuilder.append(StringBuilder.java:288)
at com.android.internal.os.LoggingPrintStream.append(LoggingPrintStream.java:333)
at com.android.internal.os.LoggingPrintStream.append(LoggingPrintStream.java:36)
at java.lang.Throwable.printStackTrace(Throwable.java:315)
at java.lang.Throwable.printStackTrace(Throwable.java:282)
at java.lang.Throwable.printStackTrace(Throwable.java:236)
at com.radioafrica.mpasho.object.Article.(Article.java:31)
at com.radioafrica.mpasho.loader.FeedsLoader.loadInBackground(FeedsLoader.java:50)
at com.radioafrica.mpasho.loader.FeedsLoader.loadInBackground(FeedsLoader.java:24)
at android.support.v4.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:242)
at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:51)
at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:40)
at android.support.v4.content.ModernAsyncTask$2.call(ModernAsyncTask.java:123)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
The error occurs when i try to load the data via an asynctaskloader before passing the data to the adapter.