B4J Question [Solved] ChoiceBox is very slow or app crashes [out of memory]

Mark Read

Well-Known Member
Licensed User
Longtime User
I am in the early days of this app. Important here are the two Mime Type choice boxes. Selecting the upper one will fill the lower one. Any selection in the first, EXCEPT Application, works fine and is fast enough. Selecting application either breaks the app (no further selection possible) or after a short time I get a java heap error, out of memory.

The csv files are included, most have less than 100 entries but the application has 1168.

Any help would be appreciated.
 

Attachments

  • desktop-ver1.zip
    29.3 KB · Views: 333

Daestrum

Expert
Licensed User
Longtime User
I had this too, I simply changed the choicebox to a combobox, they work in a similar fashion, but combo fills very much faster.

(Also in your code check the line you read in for ,,(comma comma) and replace with , ,(comma space comma) or you get nullpointer)

Modified code so you don't need the file > list > mime2
B4X:
    Dim reader As TextReader    
        reader.Initialize(File.OpenInput(File.DirAssets,csvFile))
        Dim line As String = " "
    'Dim Mylist As List
    cbMime2.Items.Clear
    'Mylist.Initialize
        line = reader.ReadLine ' eat the headers
        Do While reader.ready
        line = reader.ReadLine.Replace(",,",", ,")
        if line.EndsWith(",") Then line = line & " "   ' can cause odd things if no value after ,
           Dim result() As String
        result=Regex.Split(",",line)
        Log(result(0) & " | " & result(1) & " | " &result(2))
        cbMime2.Items.Add(result(0) & " - " & result(1))
        'Mylist.add(line)
        Loop
    'Log("CSV size: " & Mylist.Size)
        reader.Close
'    cbMime2.Items.Clear
'    For Each i As String In Mylist
'        Dim result() As String
'        result=Regex.Split(",",i)
'        Log(result(0) & " | " & result(1) & " | " &result(2))
'        cbMime2.Items.Add(result(0) & " - " & result(1))
'    Next
    Log(cbMime2.Items.Size)

Or use StringUtils.readCSV to read the file.
 
Last edited:
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
@Daestrum : WOW! This rocks. Not only does it work perfectly but it is extremely fast!! I never realised that the different views could have such a huge difference in the population time. But it still makes me wonder why? I think this is a valuable piece of info for other users. I will knock up a small test app to show the time difference for a listview/choicebox/combobox, as it would be interesting.

Thanks a bunch.
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
JFI - Tested using 1168 Entries and modified code as above on my PC.
ChoiceBox = crashed
ComboBox = finished in 47 milliseconds
ListView = finished in 32 milliseconds

Update: ChoiceBox = 212125 milliseconds when it doesn't crash with out of memory error.
 
Last edited:
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Had a look round the web re ChoiceBox, seems it's only useful if it has around 10 items or less. Any more and you start seeing massive delays when populating it.
Opinions on various sites say 10 items or less use ChoiceBox , more than 10 items use a ComboBox.
 
Upvote 0
Top