B4J Question [BANano] Class Instance Resides in Memory?

Mashiane

Expert
Licensed User
Longtime User
Ola

I dont know how to explain this. I am under the impression that when you call Dim x as Class and call x.Initialize for a class call, it completely creates a new instance of the class.

It seems like this is not the case with javascript as one would expect with B4J happening.

I will try and reproduce this.

An example is based on this assumption.

Create a class
Define a global variable in the class as a list
in initialize of the class call list.initialize
Somewhere on your code, call a sub that will assign a null to the list.
Have a click button that will dim x as class and initialize it. Call the sub that will set the list to null.
Click the button, for the first time the app runs well.
Click the button again, the app crashes with cannot set length to null.

#thoughts / #confused
 

alwaysbusy

Expert
Licensed User
Longtime User
I can not reproduce this:

TestClass:
B4X:
Sub Class_Globals
    Dim lst As List
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    lst.Initialize
End Sub

public Sub SetNull()
    lst = Null
End Sub

Main:
B4X:
Sub Button1_Click (event As BANanoEvent)
    Log("button 1 click")

    Dim cls As TestClass
    cls.Initialize
    cls.SetNull    
End Sub

Alwaysbusy
 
Upvote 0
Top