Gson: GsonResponseBodyConverter - java.lang.OutOfMemoryError

Created on 17 Oct 2018  路  1Comment  路  Source: google/gson

Hi,

Recently, i got this exception from my application, may not be due to source code or my data.

Caused by java.lang.OutOfMemoryError: Failed to allocate a 30536292 byte allocation with 4194304 free bytes and 28MB until OOM
at java.util.ArrayList.add(ArrayList.java:118)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(SourceFile:1083)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(SourceFile:129)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(SourceFile:220)
at retrofit2.converter.gson.GsonResponseBodyConverter.convert(SourceFile:37)
at retrofit2.converter.gson.GsonResponseBodyConverter.convert(SourceFile:25)
at retrofit2.ServiceMethod.toResponse(SourceFile:118)
at retrofit2.OkHttpCall.parseResponse(SourceFile:212)
at retrofit2.OkHttpCall.execute(SourceFile:174)
at retrofit2.adapter.rxjava.CallExecuteOnSubscribe.call(SourceFile:40)
at retrofit2.adapter.rxjava.CallExecuteOnSubscribe.call(SourceFile:24)
at retrofit2.adapter.rxjava.BodyOnSubscribe.call(SourceFile:33)
at retrofit2.adapter.rxjava.BodyOnSubscribe.call(SourceFile:25)
at rx.internal.operators.OnSubscribeLift.call(SourceFile:1048)
at rx.Observable.unsafeSubscribe(SourceFile:10151)
at rx.internal.operators.OnSubscribeMap.call(SourceFile:1048)
at rx.internal.operators.OnSubscribeLift.call(SourceFile:1048)
at rx.Observable.unsafeSubscribe(SourceFile:10151)
at rx.internal.operators.OnSubscribeMap.call(SourceFile:1048)
at rx.internal.operators.OnSubscribeLift.call(SourceFile:1048)
at rx.Observable.unsafeSubscribe(SourceFile:10151)
at rx.internal.operators.OperatorSubscribeOn$1.call(SourceFile:94)
at rx.internal.schedulers.ScheduledAction.run(SourceFile:55)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
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)

Please help me resolve this!

Thanks.
com.google.code.gson:gson:2.8.2

Most helpful comment

OOMs are never caused directly by the stacktrace which they contain. There is usually a build-up of events which lead to them. This is a combination of leaks (intentional or not) or producers which outrun their consumers or any number of other causes.

Suffice to say, Gson is doing what you told it. Trying to allocate a 30MB something which your JSON and model dictated was required. The OOM comes from the JVM being unable to provide Gson with what it requested, and not from Gson itself.

>All comments

OOMs are never caused directly by the stacktrace which they contain. There is usually a build-up of events which lead to them. This is a combination of leaks (intentional or not) or producers which outrun their consumers or any number of other causes.

Suffice to say, Gson is doing what you told it. Trying to allocate a 30MB something which your JSON and model dictated was required. The OOM comes from the JVM being unable to provide Gson with what it requested, and not from Gson itself.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GoogleCodeExporter picture GoogleCodeExporter  路  15Comments

GoogleCodeExporter picture GoogleCodeExporter  路  25Comments

danieleguiducci picture danieleguiducci  路  34Comments

GoogleCodeExporter picture GoogleCodeExporter  路  19Comments

cayhorstmann picture cayhorstmann  路  13Comments