B4J Question Delete the form completely

nima66

Member
I have created several separate forms in several classes.
By selecting in the application menu, the variable corresponding to each class is initialized and the form is displayed.
I need the form to be completely deleted whenever the form is closed.
When the form is closed, it is not actually deleted and cleared from memory. (Because when the form is show again, the last state is displayed again)
How can I completely delete the form (to optimize memory) so that the class type variable is reinitialized upon redisplay?
 

nima66

Member
Calling Dim and Initialize will create a new form and if there are no other references to the previous form then it will be cleared from memory.
The problem is that I have a main form containing the application menu.
In this class I have defined some public variables from other classes to create and display other forms.
The reason for this was that in each form I need some public variables in other forms.
Suppose the menu class is named mainMenu.
In class a I will access the variable of class b.
mainMenu.b.var = "test"
If I want all variables of class b to be reset and created from scratch, I need to reinitialize the variable in the menu class.
I am worried that the previous initialization will take up memory.
 
Upvote 0

nima66

Member
There are very few cases with B4X, where you really need to worry about memory usage. Implement your solution in the way that is most simple for you. Only if you actually see the memory keep rising and eventually hit an out of memory error then you need to think about memory usage.
thanks Erel
I was worried because on Android memory usage leads to slow app execution.
So on Windows it probably isn't the case.
I used to work with C# and memory optimization was very important.
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
The problem is that I have a main form containing the application menu.
Depending on how many menu options you need you could consider having a "shared" menu on each B4XPage. Then you can keep and update the variable in the B4XMainPage and only use the B4Xmenu outside the B4XMainPage. You can write and read it from a file or via [B4X] KVS2 / KeyValueStore 2 - Simple & Powerful Local Datastore. With the KVS2 solution you can save the variable and then continue where you left off after reading it back.
 
Upvote 0

nima66

Member
Depending on how many menu options you need you could consider having a "shared" menu on each B4XPage. Then you can keep and update the variable in the B4XMainPage and only use the B4Xmenu outside the B4XMainPage. You can write and read it from a file or via [B4X] KVS2 / KeyValueStore 2 - Simple & Powerful Local Datastore. With the KVS2 solution you can save the variable and then continue where you left off after reading it back.
Thanks for your help
I am not using B4XPage.
I wrote code that converts about 60% of the b4a source to b4j.
I did not write the b4a source with B4XPage.
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
Developing in B4XPages offers the advantage that you can divide the source code over multiple pages. This makes your program code easier to maintain and reusable. By choosing to use B4X program solutions as much as possible, it becomes possible (but not necessary) to use your program in multiple platforms. I am currently working on writing an expandable menu in B4J that also works in B4A. Only old B4A source code sometimes needs to be modernized due to the many adjustments in Android.
 
Upvote 0
Top