Out of Memory Error on writing file:Play store crash report

thedesolatesoul

Expert
Licensed User
Longtime User
I get a crash on my app when trying to write out an object( a list of custom types).
I dont really understand this, because i dont get the crash on holding the data in memory, but i get the crash when writing out to file? Am I allocating more memory when doing writeobject? Is it because my OutputStream has a buffer that goes over memory?
B4X:
java.lang.OutOfMemoryError
at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:91)
at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:201)
at java.util.zip.DeflaterOutputStream.deflate(DeflaterOutputStream.java:139)
at java.util.zip.DeflaterOutputStream.write(DeflaterOutputStream.java:200)
at java.util.zip.GZIPOutputStream.write(GZIPOutputStream.java:104)
at java.io.DataOutputStream.write(DataOutputStream.java:98)
at java.io.ObjectOutputStream.writeNewString(ObjectOutputStream.java:1449)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1657)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.writeObject(RandomAccessFile.java:438)
at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.writeMap(RandomAccessFile.java:506)
at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.writeType(RandomAccessFile.java:479)
at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.writeObject(RandomAccessFile.java:442)
at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.writeList(RandomAccessFile.java:557)
at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.writeObject(RandomAccessFile.java:430)
at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.writeMap(RandomAccessFile.java:506)
at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.writeType(RandomAccessFile.java:479)
at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.writeObject(RandomAccessFile.java:442)
at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.writeList(RandomAccessFile.java:557)
at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.writeObject(RandomAccessFile.java:430)
at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.writeHelper(RandomAccessFile.java:318)
at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.WriteObject(RandomAccessFile.java:303)
at com.maximussoft.cloudpipes.filehelper._vvvvvvvvvvvvvvvvvv5(filehelper.java:803)
at com.maximussoft.cloudpipes.dpservice._vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv5(dpservice.java:2778)
at com.maximussoft.cloudpipes.dpservice._response_streamfinish(dpservice.java:2223)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:136)
at anywheresoftware.b4a.BA$2.run(BA.java:244)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4517)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
at dalvik.system.NativeStart.main(Native Method)
 

thedesolatesoul

Expert
Licensed User
Longtime User
Hi Erel,
This size of this list is dynamic.
Basically it is the transfer list (much like a download list). If the user downloads 100 files, there will be 100 objects in it, and so on.

This is what the type looks like:
B4X:
Type TransferListType (      _
      Index        As Int,     _
      Title        As String,  _
      ChildFiles   As List,    _
      ChildExists  As Boolean, _
      Expanded     As Boolean, _
      TotalSize    As Long,    _
      TotalDone    As Long     _
      )
      
   Type SingleFileTransferType ( _
      Index        As Int,      _
      FilePath     As String,   _
      FileDate     As Long,     _
      FileStatus   As String,   _
      FileProgress As Int,      _
      FileSize     As Long,     _
      FileDone     As Long,     _
      OpType       As Int)      
      
      
   Dim TransferList As List

This is used to write it out:
B4X:
   F.WriteObject(dpservice.TransferList,True,0)
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
How did you decipher that it is the title?
The title is usually really small, its either just the directory name, or a small pipe name...i dont expect it to be more than 20 charachters.
However, the ChildFiles is a list of SingleFileTransferType (sorry, nested lists and types!). But I dont expect any of the strings to be very long.
Unless the user is really stupid and he has an extremely long directory name or something like that. May be it could be that his file got corrupt somehow (it is in DirInternal though).
Thanks.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
How did you decipher that it is the title?
You can see that it is a string that gets written from this line:
at java.io_ObjectOutputStream.writeNewString(ObjectOutputStream.java:1449)

Instead of saving the whole list at once, you can save the items one after another. First write the list size and then go over the items and write them.
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
So manually writing each object will solve the out of memory problem? Do you mean I can write an object/type but not do that with a list? Or should I write out each individual primitive myself?
Could I potentially write a generic serializer in B4A?
I did the manual write for one of my other files in order to make it transferable across packages.
Thanks.
 
Upvote 0
Top