B4J Question customlistview's memory is not released

xulihang

Active Member
Licensed User
Longtime User
I use customlistview to load tens of thousands of items with lazy load.

The layout has two textareas.

basiccat2.png

Load with empty pane:

B4X:
Sub readWorkFile(filename As String,filesegments As List,fillUI As Boolean,root As String)
   ......
        Dim segmentsList As List
        segmentsList=sourceFileMap.Get(innerFilename)
        filesegments.AddAll(segmentsList)
        If fillUI Then
            For Each bitext As List In segmentsList
                createEmptyPane(bitext)
            Next
        End If
    Next
End Sub

When visible range changed, fill the pane

B4X:
Public Sub fillPane(FirstIndex As Int, LastIndex As Int)
    If segments.Size=0 Then
        Return
    End If
    Dim ExtraSize As Int
    ExtraSize=15
    For i = Max(0,FirstIndex-ExtraSize*2) To Min(Main.editorLV.Size - 1,LastIndex+ExtraSize*2)
        Dim segmentPane As Pane
        segmentPane=Main.editorLV.GetPanel(i)
        If i > FirstIndex - ExtraSize And i < LastIndex + ExtraSize Then
            'visible+
            segmentPane.Enabled=True
            If segmentPane.NumberOfNodes = 0 Then
                Dim bitext As List
                bitext=segments.Get(i)
                addTextAreaToSegmentPane(segmentPane,bitext.Get(0),bitext.Get(1))
            End If
        Else
            'not visible
            segmentPane.Enabled=False
            If segmentPane.NumberOfNodes > 0 Then
                segmentPane.RemoveAllNodes '<--- remove the layout
            End If
        End If
    Next
End Sub

When I call clv.clear, the memory is not released.

basiccat1.png


Is this because the customlistview is a global variable?
 

Harris

Expert
Licensed User
Longtime User
i want users to scroll to any position they want. loading more when the scrollbar reach end is not convenient

And scrolling thru 50k of items (or more when loaded after) is convenient? Even with a fast swiping finger - that would take all day...

You will come to an acceptable solution thru suggestions of dealing with this. Seems to me you need to narrow the scope to reduce the (big) "list".
Yet, at this juncture, we really don't have a good understanding of what "the" scope is...
Somehow, I don't think you know either... (just an observation).

Help us to help you. This is challenging - but you have a team of very intelligent peeps here to work this out.
The final resolve could help us all when dealing with such a large (possibly complicated) scope - you never know...
 
Upvote 0

xulihang

Active Member
Licensed User
Longtime User
Even with a fast swiping finger - that would take all day...

Sorry it's a desktop app not a mobile app.

It's nice to have you guys to help me and other members.

Using listview with lazyloading is okay for now. I may need to upload a demo project and you can feel its performance.
 
Upvote 0

xulihang

Active Member
Licensed User
Longtime User
This is the demo project.

The left textarea stores the source text and the right is for inputing translation. This is used in my computer-aided translation app BasicCAT.
 

Attachments

  • largeListview.zip
    3.9 KB · Views: 229
Upvote 0

Harris

Expert
Licensed User
Longtime User
upload_2018-12-23_23-30-42.png


This is what I see mid way thru your list (scrolling up and down).. which is essentially nothing...and takes sometime to produce nothing....

B4X:
For i=1 To 50000
        segments.Add(i)
        ListView1.Items.Add("")
    Next


Is 50k reasonable (as just an example, of course)? How can you range this to something that reasonable and in scope (smaller range)?
Like - "How are you today" - from en to cn... Or something along these lines?
Whats the purpose?
What needs to in "in range".
What is trying to be accomplished with this (endless list) - I don't understand...

Over the next few days, enjoy your time with family and friends - as I shall.
Happy Holidays to all...
 
Upvote 0

xulihang

Active Member
Licensed User
Longtime User
I do come across this problem. It's not perfect to get the visible range as there is no public api to get this and I can only use some hacks. Scroll a little bit will show the content though the UX is not good.

Normally, documents should be split to smaller parts. But in case the entire document is loaded, I have to make sure that it runs smoothly. Commercial CAT tools all can do this without a problem. 50k is like an extremity test.

My app segments texts into sentences. Sentences are hold in the segments List and get loaded when its index are in the visible range. It is easier to handle that the segments List's index is correlated to the ListView's.

The SnowmanCAT:

snowmancat-png.75605



And Happy new year!
 

Attachments

  • snowmancat.png
    snowmancat.png
    29.3 KB · Views: 348
Upvote 0

xulihang

Active Member
Licensed User
Longtime User
I add a sleep(50) before getting the visible range. It seems to solve the blank item problem

B4X:
Sub checkVisibleRange
    Sleep(50)
    Dim currentVisibleRange As Range
    currentVisibleRange=getVisibleRange
......
En Sub
 
Upvote 0
Top