Showing my application error log (saved to a list and concatenated to a string ready to be processed by a BBCodeView) in a dialog.
This is a large list (just for testing, all errors have been fixed) with some 80 items.
All the error items in the BBCodeView have an item number and these are clickable, so I can either copy the error text to the clipboard
or clear the particular error item from the list.
After showing this text in the BBCodeView and clearing the first item then after doing this some 3 to 6 times (variable) I get an out of memory
error on putting the concatenated list items in the BBCodeView.
There are either of these 2 similar errors:
This is the code that processes the concatenated list items:
And this is the code that concatenates the list items:
The strange thing is that although the string to be passed to the BBCodeView is getting smaller (by clearing the first error item) the error only appears after some 3 to 6
runs. I had a good search for this problem in the forum, but couldn't find anything helpful.
Any ideas what might be the problem here?
RBS
This is a large list (just for testing, all errors have been fixed) with some 80 items.
All the error items in the BBCodeView have an item number and these are clickable, so I can either copy the error text to the clipboard
or clear the particular error item from the list.
After showing this text in the BBCodeView and clearing the first item then after doing this some 3 to 6 times (variable) I get an out of memory
error on putting the concatenated list items in the BBCodeView.
There are either of these 2 similar errors:
B4X:
bctextengine$_bcglyphInitialize (java line: 331)
java.lang.OutOfMemoryError: Failed to allocate a 40 byte allocation with 2564328 free bytes and 2504KB until OOM, target footprint 268435456, growth limit 268435456; giving up on allocation because <1% of heap free after GC.
at b4a.exampleljjll.bctextengine$_bcglyph.Initialize(bctextengine.java:331)
at b4a.exampleljjll.bctextengine._createglyphfromdefaultcolor(bctextengine.java:835)
at b4a.exampleljjll.bctextengine._createglyph(bctextengine.java:721)
at b4a.exampleljjll.bctextengine._createsinglesection(bctextengine.java:976)
at b4a.exampleljjll.bctextengine._createunbreakable(bctextengine.java:1073)
at b4a.exampleljjll.bctextengine._handletextrun(bctextengine.java:1790)
at b4a.exampleljjll.bctextengine._prepare(bctextengine.java:2474)
at b4a.exampleljjll.bctextengine._prepareforlazydrawing(bctextengine.java:2500)
at b4a.exampleljjll.bbcodeview._redraw(bbcodeview.java:522)
at b4a.exampleljjll.bbcodeview._parseanddraw(bbcodeview.java:497)
at b4a.exampleljjll.bbcodeview._settext(bbcodeview.java:549)
at b4a.exampleljjll.b4xdialog2$ResumableSub_ShowWithBCTE.resume(b4xdialog2.java:3751)
at b4a.exampleljjll.b4xdialog2._showwithbcte(b4xdialog2.java:2861)
at b4a.exampleljjll.b4xmainpage$ResumableSub_ShowErrorLog.resume(b4xmainpage.java:24831)
at b4a.exampleljjll.b4xmainpage._showerrorlog(b4xmainpage.java:24756)
at b4a.exampleljjll.b4xmainpage$ResumableSub_ShowAbout.resume(b4xmainpage.java:23897)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:275)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:215)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.keywords.Common$15.run(Common.java:1804)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8747)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
B4X:
bctextengine_createglyphfromdefaultcolor (java line: 853)
java.lang.OutOfMemoryError: Failed to allocate a 2072 byte allocation with 2090368 free bytes and 2041KB until OOM, target footprint 268435456, growth limit 268435456; giving up on allocation because <1% of heap free after GC.
at b4a.exampleljjll.bctextengine._createglyphfromdefaultcolor(bctextengine.java:853)
at b4a.exampleljjll.bctextengine._createglyph(bctextengine.java:721)
at b4a.exampleljjll.bctextengine._createsinglesection(bctextengine.java:976)
at b4a.exampleljjll.bctextengine._createunbreakable(bctextengine.java:1073)
at b4a.exampleljjll.bctextengine._handletextrun(bctextengine.java:1790)
at b4a.exampleljjll.bctextengine._prepare(bctextengine.java:2474)
at b4a.exampleljjll.bctextengine._prepareforlazydrawing(bctextengine.java:2500)
at b4a.exampleljjll.bbcodeview._redraw(bbcodeview.java:522)
at b4a.exampleljjll.bbcodeview._parseanddraw(bbcodeview.java:497)
at b4a.exampleljjll.bbcodeview._settext(bbcodeview.java:549)
at b4a.exampleljjll.b4xdialog2$ResumableSub_ShowWithBCTE.resume(b4xdialog2.java:3751)
at b4a.exampleljjll.b4xdialog2._showwithbcte(b4xdialog2.java:2861)
at b4a.exampleljjll.b4xmainpage$ResumableSub_ShowErrorLog.resume(b4xmainpage.java:24830)
at b4a.exampleljjll.b4xmainpage._showerrorlog(b4xmainpage.java:24758)
at b4a.exampleljjll.b4xmainpage$ResumableSub_ProcessError.resume(b4xmainpage.java:19759)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:275)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:215)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.keywords.Common$15.run(Common.java:1804)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8747)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
This is the code that processes the concatenated list items:
B4X:
If tDP.bPrompt Then
If TextEngine.IsInitialized = False Then
TextEngine.Initialize(Parent)
End If
bbcvPrompt.TextEngine = TextEngine
bbcvPrompt.LazyLoading = True 'but already set so in the designer
bbcvPrompt.mBase.Height = tDP.iScrollViewHeight 'this is the visible height of the old plain prompt view
bbcvPrompt.mBase.Top = tDP.iPromptTop
bbcvPrompt.mBase.Width = tDP.iScrollViewWidth 'this is same as tDP.iPromptWidth
If tDP.bPromptScroll Then
bbcvPrompt.sv.Height = tDP.iScrollViewHeight
End If
Dim rectPadding As B4XRect
rectPadding.Initialize(arrPromptPadding(0), arrPromptPadding(1), arrPromptPadding(2), arrPromptPadding(3))
bbcvPrompt.Padding = rectPadding
'------------------------------------------------'
'This is the way to set the BBCodeView background'
'------------------------------------------------'
bbcvPrompt.mBase.Color = iPromptColour
bbcvPrompt.sv.Color = iPromptColour
bbcvPrompt.sv.ScrollViewInnerPanel.Color = iPromptColour
Log("ShowWithBCTE, before adding text")
If tDP.bcsPrompt Then
bbcvPrompt.Text = csPrompt 'this won't happen
Else
bbcvPrompt.Text = strPrompt '<<<<<<< out of memory error happening here
End If
Log("ShowWithBCTE, after adding text")
'get rid of the click sound as there will be nil clickable
'---------------------------------------------------------
Dim jo As JavaObject = bbcvPrompt.mBase
jo.RunMethod("setSoundEffectsEnabled", Array(False))
End If 'If tDP.bPrompt
And this is the code that concatenates the list items:
B4X:
Sub ConcatenateListItems(lst As List, strSeparator As String, bAddIndex As Boolean, bClickableNumbers As Boolean) As String
Dim i As Int
Dim strResult As String
Dim strURLStart As String
Dim strURLEnd As String
If bClickableNumbers Then
strURLStart = "[url]"
strURLEnd = "[/url]"
End If
If bAddIndex Then
For i = 0 To lst.Size - 1
If i = 0 Then
strResult = strURLStart & (i + 1) & ") " & strURLEnd & lst.Get(i)
Else
strResult = strResult & strSeparator & strURLStart & (i + 1) & ") " & strURLEnd & lst.Get(i)
End If
Next
Else
For i = 0 To lst.Size - 1
If i = 0 Then
strResult = lst.Get(i)
Else
strResult = strResult & strSeparator & lst.Get(i)
End If
Next
End If
Return strResult
End Sub
The strange thing is that although the string to be passed to the BBCodeView is getting smaller (by clearing the first error item) the error only appears after some 3 to 6
runs. I had a good search for this problem in the forum, but couldn't find anything helpful.
Any ideas what might be the problem here?
RBS