Another late update (I was very busy with test papers this week). Just in case someone who has the same memory problem, the factory reset I did as mentioned above didn't work for long. I'm back to getting the out of memory problem. Here are the other things I did so far in an attempt to solve the problem, creating a new file on each compile/run:
-- used B4XSerializator instead, as suggested by Erel above
-- initialized the List contained inside the user type I'm trying to save to and read from the file
-- removed the list altogether
-- tried to read only a single data entry from file (to remove the Do-Loop)
-- set all the variables to simple data (123 for Int, "text" for string, etc.) to ensure correct ones are being saved to file
-- (BUT THIS ONE WORKS FINE!!!) tried to save/read bitmaps instead (many times bigger in size) on the very line that generate the OOM error
Therefore, I think the problem is in the user type I'm trying to save to/read from the file. It is declared in the Main module this way:
Type UserLog(DateTime_Start As Long, TaskDuration As Int, ReadingMaterialTitle As String, ReadingMaterialFname As String, TotalWords As Int, SkippedWords As String, PercentDone As Int, Score As Int, SpeedWPM As Int, Remarks As String)
And, it is saved this way:
Dim newlog As UserLog
newlog.Initialize
newlog.DateTime_Start = 123456789 'Main.CurUserLog.DateTime_Start
newlog.PercentDone = 123 'Main.CurUserLog.PercentDone
newlog.ReadingMaterialFname = "try string" 'Main.CurUserLog.ReadingMaterialFname
newlog.ReadingMaterialTitle = "Sample Title" 'Main.CurUserLog.ReadingMaterialTitle.Replace(",", "")
newlog.Remarks = "Remarks" 'Main.CurUserLog.Remarks
newlog.Score = 123 'Main.CurUserLog.Score
newlog.SkippedWords = "tryskip" 'Main.CurUserLog.SkippedWords
newlog.SpeedWPM = 123 'Main.CurUserLog.SpeedWPM
newlog.TaskDuration = 123 'Main.CurUserLog.TaskDuration
newlog.TotalWords = 123 'Main.CurUserLog.TotalWords
Main.lstSessionLogs.Add(newlog) 'add to current session's logs
'append new data to file right away
Dim ufile As String
If Login.CurUserInfo.IsInitialized Then
If Login.CurUserInfo.Username.Trim <> "" Then
ufile = Login.CurUserInfo.Username.Trim & "_tlogs.dat"
Else
ufile = "UserTaskLogs2.dat"
End If
Else
ufile = "UserTaskLogs2.dat"
End If
Log("ufile:" & ufile)
Dim raf As RandomAccessFile
raf.Initialize(File.DirInternal, ufile, False)
raf.WriteB4XObject(newlog, raf.Size) 'add to end of file
raf.Close
It is read from file using this code:
If File.Exists(File.DirInternal, ufile) = True Then
Dim raf As RandomAccessFile
raf.Initialize(File.DirInternal, ufile, True)
Do While raf.CurrentPosition < raf.Size
Dim UL As UserLog
UL = raf.ReadB4XObject(raf.CurrentPosition) '<------this line throws the OOM error
Main.lstUserTaskLogs.Add(UL)
Loop
raf.Close
End If