I thought it would be interesting to discuss memory management in java and in b4a in particular. I come from more than 30 years of allocating and deallocating memory for pointers, objects, etc. In java it is generally not necessary, and is widely frowned upon to do memory optimizations. The garbage collector handles that stuff as needed. I still have questions though, even after reading through the whitepapers for java memory and garbage collection.
In my current file manager app I am using a multi-dimensional array of labels to list information about each file. The array holds up to 1000 sets of 6 labels (name, size, date, time, permissions, and a bitmap). They are then displayed on a scrollview.
Each time the user changes directories, I clear the current contents of all the labels and assign null to each label. I understand that this does not release the labels, but it does release the memory held by their contents (I think).
So the question I have is: Is there a better way to do this? The garbage collector won't mess with any object that is still referenced, and all of the labels in the array are always referenced. So, as I understand it, unless I clear the contents each time, I get something like:
A user goes into a dir with 300 .mp3's in it, does something, then goes to a dir with 5 entries in it. Unless I clear the old entries, I still have 295 entries full of stuff I no longer need that the garbage collector will ignore.
Am I understanding this correctly so far? No, I can't do what I need with a listview, it isn't flexible enough to display different colors for different entry types, etc.
Suggestions?
--- Jem
In my current file manager app I am using a multi-dimensional array of labels to list information about each file. The array holds up to 1000 sets of 6 labels (name, size, date, time, permissions, and a bitmap). They are then displayed on a scrollview.
Each time the user changes directories, I clear the current contents of all the labels and assign null to each label. I understand that this does not release the labels, but it does release the memory held by their contents (I think).
So the question I have is: Is there a better way to do this? The garbage collector won't mess with any object that is still referenced, and all of the labels in the array are always referenced. So, as I understand it, unless I clear the contents each time, I get something like:
A user goes into a dir with 300 .mp3's in it, does something, then goes to a dir with 5 entries in it. Unless I clear the old entries, I still have 295 entries full of stuff I no longer need that the garbage collector will ignore.
Am I understanding this correctly so far? No, I can't do what I need with a listview, it isn't flexible enough to display different colors for different entry types, etc.
Suggestions?
--- Jem