0

I got outofmemory exception while converting json file to list using Gson

Caused by 
java.lang.OutOfMemoryError
Failed to allocate a 18874376 byte 
allocation with 18575992 free 
bytes and 17MB until OOM, target 
footprint 268435456, growth limit 
268435456

@Nullable
public <T> List<T> getConvertedListFromJson(JSONArray jsonArray, Class<T> type) throws OutOfMemoryError{
    Gson gson = new Gson();

    return gson.fromJson(jsonArray.toString(), new ListOf<>(type));

}

How to over come this issue

1 Answers1

0

OutOfMemoryError usually means that you’re doing something wrong, either holding onto objects too long or trying to process too much data at a time. Sometimes, it indicates a problem that’s out of your control, such as a third-party library that caches strings or an application server that doesn’t clean up after deploys. And sometimes, it has nothing to do with objects on the heap.

  • Yes atleast 5000 jsonarray records converted to list using Gson – user9298460 Sep 02 '22 at 08:32
  • Crash occured only in redmi8 mobile – user9298460 Sep 02 '22 at 08:33
  • try to create thread and use your code there may be OS would have been blocking something into redmi device – Malik Farooq Sep 02 '22 at 11:50
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – jasie Sep 07 '22 at 07:22