Android Question Control/View re-use best practice?

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
I'm using a control that I've created that may display several different UI layouts depending on the required situation many times over the course of the activity lifetime (which could be days without reboot/restart). Each UI layout may have 500 or more views contained therein which I do have record of in a standard LIST object.

This leads to my question: When clearing out the current layout in favor of displaying/loading a new layout, which method below is optimal or does it matter at all to the Android garbage collector?
  1. Individually .RemoveView on each UI element then clear my list of UI elements.
  2. Just use .RemoveAllViews on the UI parent panel then clear the list of UI elements.
  3. Just clear the list of UI elements and .Initialize the parent panel again.
  4. Some other procedure I've missed in the seemingly endless plethora of Android API updates.
I'm coming from a .NET background and I'm very OCD when it comes to Using/End Using and making sure I .Dispose objects. In .NET I've been caught by memory leaks/connection pool issues many times in the past due to this. The lais sez-faire resource allocation of Android devices confuses/concerns me.

Thanks in advance for any input.
 

LucaMs

Expert
Licensed User
Longtime User
I'm using a control that I've created that may display several different UI layouts depending on the required situation many times
Even a simple panel allows you to load one layout at a time; what's special about this view?

Each UI layout may have 500 or more views contained therein which I do have record of in a standard LIST object.
Too many views, I think.
https://www.b4x.com/android/forum/t...ew-lazy-loading-virtualization.87930/#content
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
@LucasMs, nothing is special about the panel the control may preset one of a few different "layouts" or "designer views" if you will, depending on user request. I'm re-using the same control and container panel to present the different views (i.e. old views will get destroyed and new ones will be created). The CLV lazy loading is a valid point for sure, but my question still remains:

If you're cycling through a large number of views over an extended period of "up time" what's the best way to get rid of the views you no longer need? Or do you even need to worry about it?
 
Upvote 0
Top