Android Question Dealing with unneeded views

galimpic

Member
Licensed User
Longtime User
This may not be specifically a B4A question: If i have a view that was created in a Sub (so no global variable points to it), and added it to a panel, is it going to be garbage collected after I remove it using Panel.RemoveAllViews, or is it going to stick around in limbo? Please no guesses, I can guess as well :)
 

Roycefer

Well-Known Member
Licensed User
Longtime User
There's no such thing as "in limbo" in Java. If an object is not referred to by anything, it is considered "dead" and marked for garbage collected at the VM's leisure.

Note the part about the VM's leisure, though. Garbage collection can slow down program execution so the VM may opt to only execute GC when it is needed (like when getting close to having the heap filled up). You can request that the VM perform GC by calling System.gc() (using Reflection or JavaObject) but this is, at best, a polite request. The VM can dismiss the request.
 
Upvote 0

galimpic

Member
Licensed User
Longtime User
Well, I understand that if nothing references it, it will be freed. However, we are not using Java, but B4A and the views are in wrappers etc. and it still may be in some list in the underlying Java code. That's why I am seeking a qualified answer, i.e. if someone actually checked by performing a memory test or something to make sure.
 
Upvote 0

galimpic

Member
Licensed User
Longtime User
Great, thank's for pointing me in the right direction. I will create a test code with many initialize/add/remove instances and see if the memory will behave. I will report here.
 
Upvote 0
Top