SeaCay Member Licensed User Longtime User Aug 25, 2012 #1 Hello All, I was wondering what does RemoveView or RemoveViewAt actually do. The wiki says "Removes this view from its parent." I am aware that the nominated view disappears. But it crossed my mind at to whether the views are deleted from memory or can the views be-instantiated? Further thoughts were if the view was only hidden, and I no longer need the view, do I need to perform any memory management/garbage collection to prevent memory leaks or is there no concern of this nature at all? Thanks for your help on this question regards SeaCay
Hello All, I was wondering what does RemoveView or RemoveViewAt actually do. The wiki says "Removes this view from its parent." I am aware that the nominated view disappears. But it crossed my mind at to whether the views are deleted from memory or can the views be-instantiated? Further thoughts were if the view was only hidden, and I no longer need the view, do I need to perform any memory management/garbage collection to prevent memory leaks or is there no concern of this nature at all? Thanks for your help on this question regards SeaCay
Olaan Expert Licensed User Longtime User Aug 25, 2012 #2 Hi, Try this code below Sub RemoveAllViews Dim I As Int For I = Activity.NumberOfViews - 1 To 0 Step -1 Activity.RemoveViewAt(I) Next End Sub Best Regards Theera Upvote 0
Hi, Try this code below Sub RemoveAllViews Dim I As Int For I = Activity.NumberOfViews - 1 To 0 Step -1 Activity.RemoveViewAt(I) Next End Sub Best Regards Theera
margret Well-Known Member Licensed User Longtime User Aug 25, 2012 #3 If you use RemoveView: The Views are removed and sent to the collector. The OS will clear the memory when needed. You do not need to perform anything further. If you wish to use the view again you will have to redefine the view, creating a new view. Upvote 0
If you use RemoveView: The Views are removed and sent to the collector. The OS will clear the memory when needed. You do not need to perform anything further. If you wish to use the view again you will have to redefine the view, creating a new view.
agraham Expert Licensed User Longtime User Aug 25, 2012 #4 That's not entirely true. RemoveView removes a View from the ViewGroup of its parent and that is all. The View is only collected by the GC if no further references to it exist. You can keep a reference to a removed View in a variable and add it back to another (or the same) Panel or Activity without having to reinstantiate it. Upvote 0
That's not entirely true. RemoveView removes a View from the ViewGroup of its parent and that is all. The View is only collected by the GC if no further references to it exist. You can keep a reference to a removed View in a variable and add it back to another (or the same) Panel or Activity without having to reinstantiate it.
warwound Expert Licensed User Longtime User Aug 25, 2012 #5 agraham said: You can keep a reference to a removed View in a variable and add it back to another (or the same) Panel or Activity without having to reinstantiate it. Click to expand... You cant' keep a reference to a View and use the same instance of that View in another Activity i thought? Aren't Views created with the Context of the Activity that calls their constructor? Martin. Upvote 0
agraham said: You can keep a reference to a removed View in a variable and add it back to another (or the same) Panel or Activity without having to reinstantiate it. Click to expand... You cant' keep a reference to a View and use the same instance of that View in another Activity i thought? Aren't Views created with the Context of the Activity that calls their constructor? Martin.
agraham Expert Licensed User Longtime User Aug 25, 2012 #6 agraham said: and add it back to another (or the same) Panel or <clarify>the same </clarify>Activity without having to reinstantiate it. Click to expand... Upvote 0
agraham said: and add it back to another (or the same) Panel or <clarify>the same </clarify>Activity without having to reinstantiate it. Click to expand...
margret Well-Known Member Licensed User Longtime User Aug 25, 2012 #7 If you have the code below. Once you click Button1, what else is required for the collector to recover the memory used by this Panel? Code: Sub Globals Dim ab As Panel ab.Initialize("ab") Activity.AddView(ab, 10, 10, 1000, 500) ab.Color = Colors.Red End Sub Sub Button1_Click ab.RemoveView End Sub Upvote 0
If you have the code below. Once you click Button1, what else is required for the collector to recover the memory used by this Panel? Code: Sub Globals Dim ab As Panel ab.Initialize("ab") Activity.AddView(ab, 10, 10, 1000, 500) ab.Color = Colors.Red End Sub Sub Button1_Click ab.RemoveView End Sub
margret Well-Known Member Licensed User Longtime User Aug 25, 2012 #9 @agraham, I ran a test on this and just like you said, you can add it back to another panel, etc. Awesome, thanks for the information and clarification on this subject. It's great to learn something new!! Upvote 0
@agraham, I ran a test on this and just like you said, you can add it back to another panel, etc. Awesome, thanks for the information and clarification on this subject. It's great to learn something new!!
SeaCay Member Licensed User Longtime User Aug 26, 2012 #10 Thanks everyone. I appreciate your replies. regards SeaCay Upvote 0
EduardoElias Well-Known Member Licensed User Longtime User Sep 18, 2012 #11 I am using an example i got in the forum to implement a grid, adding labels to a scrollview. I fill the scrollview with rows that are labels. That works fine. When i need to save my list, i go thru all the labels to create a list to save. I do not keep references to this labels or data in a separated list. After saving I go over the list to delete it using this code: 'Clears the table For i = svList.Panel.NumberOfViews -1 To 0 Step -1 svList.Panel.RemoveViewAt(i) Next however I found that besides the view disappears (the labels are gone from the scrollview) next time that i recreate the grid list with other items, when is the moment to save again, i go thru the list and i get the current labels, and all past ones. That means that besides RemoveViewAt remove the label it is being kept on the list and are accessible on the panel list of views. What is happening? Maybe i am not understanding something else. Thanks, Last edited: Sep 18, 2012 Upvote 0
I am using an example i got in the forum to implement a grid, adding labels to a scrollview. I fill the scrollview with rows that are labels. That works fine. When i need to save my list, i go thru all the labels to create a list to save. I do not keep references to this labels or data in a separated list. After saving I go over the list to delete it using this code: 'Clears the table For i = svList.Panel.NumberOfViews -1 To 0 Step -1 svList.Panel.RemoveViewAt(i) Next however I found that besides the view disappears (the labels are gone from the scrollview) next time that i recreate the grid list with other items, when is the moment to save again, i go thru the list and i get the current labels, and all past ones. That means that besides RemoveViewAt remove the label it is being kept on the list and are accessible on the panel list of views. What is happening? Maybe i am not understanding something else. Thanks,
Erel B4X founder Staff member Licensed User Longtime User Sep 18, 2012 #12 RemoveViewAt removes the view from the panel. If there are other references to that view (from a different list for example) then those references will still be valid. I recommend you to use CustomListView class or CheckList class instead of implementing a similar solution. Upvote 0
RemoveViewAt removes the view from the panel. If there are other references to that view (from a different list for example) then those references will still be valid. I recommend you to use CustomListView class or CheckList class instead of implementing a similar solution.