Android Question Efficient memory management.

Tom_707

Member
Licensed User
Which of these alternatives is the most efficient in terms of memory management?

1. Continually re-using the same View:
B4X:
Dim SCView As ScrollView
Dim lblTemp As Label

For Counter = 0 to 10000000
    SCView.Panel.AddView(lblTemp,....)
    .
    .
    .
    lblTemp.RemoveView
Next


2. Creating a new instance of the View every time:
B4X:
Dim SCView As ScrollView

For Counter = 0 to 10000000
    Dim lblTemp As Label

    SCView.Panel.AddView(lblTemp,....)
    .
    .
    .
    lblTemp.RemoveView
Next


3. Creating a new instance of the View and releasing the memory used by the previous instance. Is this even necessary? What command/ syntax is correct?
B4X:
Dim SCView As ScrollView

For Counter = 0 to 10000000
    Dim lblTemp As Label

    SCView.Panel.AddView(lblTemp,....)
    .
    .
    .
    lblTemp.RemoveView
    lblTemp = Null            '*Does this release an object?*'
Next
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Which of these alternatives is the most efficient in terms of memory management?
Use xCustomListView with lazy loading.

If you really want to show million items then rethink your design. No user will ever want to scroll a list with million items.

If you want to show 50k items and think that it is a good idea then use PreoptimizedCLV.
 
Upvote 0

Tom_707

Member
Licensed User
Use xCustomListView with lazy loading.

If you really want to show million items then rethink your design. No user will ever want to scroll a list with million items.

If you want to show 50k items and think that it is a good idea then use PreoptimizedCLV.
I'm not trying to create a list with a million items. The ScrollView is there just as an example. Replace ScrollView with a Panel.

And the million is there to try and convey that I have a really large loop where I am using and re-using a huge amount of Views.

I would like to know what is the most memory efficient way of doing this.
 
Upvote 0

AnandGupta

Expert
Licensed User
Longtime User
In short use PreoptimizedCLV if you can.

It is memory efficient.

Regards,

Anand
 
Upvote 0
Top