wimpie3 Well-Known Member Licensed User Longtime User Sep 19, 2016 #1 I have a hard time understanding how B4A handles DIM's and memory management. When I do this: Code: Copy for t = 1 to 100 dim s as string = "My String" next The same variable S is overwritten - the old S disappears from memory and gets a new value. No memory leak. However, when I do this: Code: Copy for t = 1 to 100 dim s as label= "My String" Activity.addview(S,0,0,100dip,100dip) next The S is still overwitten but a "copy" still stays in memory somewhere, otherwise the label wouldn't be visible. In order to regain the memory, I have to loop over the labels and remove them with removeView. Is there a kind of list or tutorial available on the things we have to clean up ourselves in code to prevent these memory leaks?
I have a hard time understanding how B4A handles DIM's and memory management. When I do this: Code: Copy for t = 1 to 100 dim s as string = "My String" next The same variable S is overwritten - the old S disappears from memory and gets a new value. No memory leak. However, when I do this: Code: Copy for t = 1 to 100 dim s as label= "My String" Activity.addview(S,0,0,100dip,100dip) next The S is still overwitten but a "copy" still stays in memory somewhere, otherwise the label wouldn't be visible. In order to regain the memory, I have to loop over the labels and remove them with removeView. Is there a kind of list or tutorial available on the things we have to clean up ourselves in code to prevent these memory leaks?
Erel B4X founder Staff member Licensed User Longtime User Sep 19, 2016 #2 Objects are released when there are no more live references to them. You don't need to "null" variables or do anything special. The garbage collector will take care of releasing the memory of unused objects. Upvote 0
Objects are released when there are no more live references to them. You don't need to "null" variables or do anything special. The garbage collector will take care of releasing the memory of unused objects.
wimpie3 Well-Known Member Licensed User Longtime User Sep 19, 2016 #3 The problem is: how do you know if objects still have live references? Is there a kind of list available in B4A that shows all objects currently in use? Upvote 0
The problem is: how do you know if objects still have live references? Is there a kind of list available in B4A that shows all objects currently in use?
Erel B4X founder Staff member Licensed User Longtime User Sep 19, 2016 #4 This is not a problem. Did you encounter an out of memory error? Upvote 0