Android Question Memory management when you DIM the same variable

wimpie3

Well-Known Member
Licensed User
Longtime User
I have a hard time understanding how B4A handles DIM's and memory management.

When I do this:
B4X:
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:
B4X:
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?
 

wimpie3

Well-Known Member
Licensed User
Longtime User
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
Top