Android Question How to Free/Release components

Discussion in 'Android Questions' started by DeviousD, Jul 16, 2015.

  1. DeviousD

    DeviousD Member Licensed User

    Morning All,

    Rather a simplistic question i suppose, but have searched the beginners guide and maybe my search terminology is not correct.

    When creating for example a label dynamically assigning values, including the tag etc how do I go about to free that component, and how to i "step" through all label components and then release/free up specific ones from the current activity? Obviously i have set the tag, but how does one step thru and release for example label99 ??

    If i'm creating labels every second, this will eventually start to take up to much memory and crash that app?

    i understand that if i call the invalidate command, it will re-draw the activity but its not what im wanting to do...
  2. eurojam

    eurojam Well-Known Member Licensed User

    Hi Devious,
    you can work with an array of labels for example. Let's say the maximum of Labels you'll need will be 100. Then you can define an Array of labels or a list or map of labels. If you don't need them anymore, you can reuse them. The amount of labels will then not be more then your is a construct like this:

    Sub Globals
    'These global variables will be redeclared each time the activity is created.
        'These variables can only be accessed from this module.
        Dim labelMap As Map
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    For i = 0 To 100
    Dim l As Label
    'the label is object and key
    End Sub
    I hope, this points in the right direction....

  3. RandomCoder

    RandomCoder Well-Known Member Licensed User

    It is my understanding that Objects will automatically be removed by the system so long as they are no longer used. To this end I think that you would need to remove the Label from the active view and ensure that you no longer reference it.
    Assuming that you're Labels are on an Activity you could itterate through all the labels and use Activity.RemoveViewAt(Index) to remove the required Label. this is also available for Panels.
    The system will the dispose of it as required.

    If you are removing a lot of Labels it might be quicker and easier to remove all the views and then load back the ones you want to keep?
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice