0

I'm facing a problem that I created innocently. So, I have this JSON that I use to store the object using SnappyDB and this object is stored because the user can send this JSON to the server when he gets online. If he is offline, the object is stored to be sent later.

My mistake was to store the object ready to be sent, i.e., I stored the JSON containning base64 of images, for example. Now I know my mistake and I've fixed storing the image path and converting just when the object will be send.

Anyways, the real problem I'm trying to fix here is that there was an object in a device that was successfully stored, but I get OutOfMemoryError when I try to access it, i.e., I didn't have any problems while serializing, but now I'm facing a problem during the deserialization. Is there anything I could do to recover this object or I can consider it as lost?

P.S.: I didn't paste the code here because It is simple enough and I solves the problem most of times. Basically I use the generic Jackson mixin

Here is the error log:

Fatal Exception: java.lang.OutOfMemoryError: Failed to allocate a 596370 byte allocation with 433384 free bytes and 423KB until OOM
       at java.lang.StringFactory.newStringFromChars(StringFactory.java)
       at java.lang.AbstractStringBuilder.toString(AbstractStringBuilder.java:629)
       at java.lang.StringBuilder.toString(StringBuilder.java:663)
       at com.fasterxml.jackson.core.util.TextBuffer.contentsAsString(TextBuffer.java:349)
       at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.getText(ReaderBasedJsonParser.java:235)
       at com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:29)
       at com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:12)
       at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:523)
       at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:95)
       at com.fasterxml.jackson.databind.deser.impl.BeanPropertyMap.findDeserializeAndSet(BeanPropertyMap.java:285)
       at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:248)
       at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:136)
       at com.fasterxml.jackson.databind.deser.std.ObjectArrayDeserializer.deserialize(ObjectArrayDeserializer.java:156)
       at com.fasterxml.jackson.databind.deser.std.ObjectArrayDeserializer.deserialize(ObjectArrayDeserializer.java:17)
       at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:523)
       at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:101)
       at com.fasterxml.jackson.databind.deser.impl.BeanPropertyMap.findDeserializeAndSet(BeanPropertyMap.java:285)
       at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:248)
       at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:169)
       at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:144)
       at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer._deserializeTypedForId(AsPropertyTypeDeserializer.java:124)
       at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer.deserializeTypedFromObject(AsPropertyTypeDeserializer.java:95)
       at com.fasterxml.jackson.databind.deser.AbstractDeserializer.deserializeWithType(AbstractDeserializer.java:131)
       at com.fasterxml.jackson.databind.deser.impl.TypeWrappedDeserializer.deserialize(TypeWrappedDeserializer.java:42)
       at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3564)
       at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2580)
       at com.ntxdev.zuptecnico.storage.BaseService.getObject(BaseService.java:31)

Since it's an Android application, the thread How to deal with “java.lang.OutOfMemoryError: Java heap space” error (64MB heap size) doesn't work for me.

Community
  • 1
  • 1
Renan Bandeira
  • 3,238
  • 17
  • 27
  • Reading the issue, it has to do with free space on your device, I've never faced this problem though. Please read this: https://docs.oracle.com/javase/7/docs/api/java/lang/OutOfMemoryError.html – Akash Agarwal Jun 14 '16 at 14:22
  • so you are trying to pus base 64 images back into a json string? – tyczj Jun 14 '16 at 14:27
  • Possible duplicate of [How to deal with "java.lang.OutOfMemoryError: Java heap space" error (64MB heap size)](http://stackoverflow.com/questions/37335/how-to-deal-with-java-lang-outofmemoryerror-java-heap-space-error-64mb-heap) – Akash Agarwal Jun 14 '16 at 14:27
  • @AkashAggarwal the problem is "how my application had enough memory to serialize and now he doesn't have to deserialize?" I've faced the problem of `OutOfMemoryError` before, but not like this. Since I'm facing the problem with Android, the mentioned thread doesn't work for me :/ – Renan Bandeira Jun 14 '16 at 15:20
  • @tyczj I was converting the images into base64 and storing in a json string, yes, but this is not the focus of the problem. I just wrote that as an explanation of how a json object could give us an `OutOfMemoryError` – Renan Bandeira Jun 14 '16 at 15:22
  • how big is this json file you have stored? have you tried not reading the whole thin in at once and streaming bits of it? – tyczj Jun 14 '16 at 16:02
  • Actually I don't know how big it is because the error is caused on a client's device. How is this technique of streaming bits of it? Can you show me an example? – Renan Bandeira Jun 14 '16 at 17:46

0 Answers0