OutOfMemoryError message at Synchronize

We are making a mobile app which saves binary data for photos on local storage.

When we sync and 21 photo's come back from server we get error message java.lang.OutOfMemoryError: Failed to allocate a 75497480 byte allocation with 25165824 free bytes and 50MB until OOM, max allowed footprint 106294448, growth limit 134217728.

After the end statement the error is produced. 

Hi Ineke,

What Platform version are you on? Also, you write that "21 photo's come back from [the] server", but your image, and the Java error, point to the photos coming back from the mobile device, and you try to store them on the server?

Hello Kilian Thanks for your reply!

My Service Studio is on version 11.6.26 build 9940.

The syncLocalRatingPhotos action is an action from the Local Storage patterns. It sync's the locally made pictures in the app to the server database and then as a last step it gives a new list of LocalRatingPhotos back to the app. (you can see the IsFromServer boolean = true) . Here on the end of the function where it gives the list back to the app it crashes with the error message.

I myself think the pictures we save in the binary field in the local entity LocalRatingPhoto are too big. Maybe we should compress them for the mobile device. However mobile devices can contain hundreds of pictures without any problem.

greetings,

Ineke


Hi Ineke,

Do you get this message on the device itself? Note that mobile devices store their pictures on the SD card or internal flash memory, but this is about RAM, not storage, as you are sending the images in a single message. I would advise you to split the handling: store the images on the server, and send a list of Ids back to the mobile app, so it can fetch the images one by one (via another REST method) and store them.

Solution

Hi Ineke,

You appear to be trying to send all your photos in a single REST request.

Try querying your local DB then looping through each photo and sending each single photo to the API one at a time (or at least just a small number of them Eg 10)

You can flag each photo successfully sent so that even if your transmission fails halfway through you will not lose the entire set.  You can resume at any time by sending the remaining unflagged photos.

Similarly on download, you can keep requesting photos 1 at a time until the server returns none.

We send hundreds of photos daily (normally in small batches but it can do lots if the mobile has been offline for a while) and have no problems like this.

Solution

Thanks very much for you help, I only added the ID's who are needed to add to the local entity table to a list and not the binary fields anymore. 

It's solved now. :-)

greetings,

Ineke