Android Question end class instance (from within)

Marc De Loose

Member
Licensed User
Longtime User
lets say i have a sub in main
B4X:
sub a
        Dim theGauge As Gauge
        theGauge.Initialize(X2,theBaseName,thePosition,theCoupledId,theCoupledIndex)

end sub

and a body delegate class(XUI2D) that has something like this in it
B4X:
public Sub Initialize (TheX2 As X2Utils,actorName As String,thePos As B2Vec2,theID As Int,theIndex As Int)
    x2=TheX2
    GaugeBaseName    = actorName
    thePosition        = thePos
    coupledID         = theID
    coupledIndex    = theIndex
    uniqueId        = DateTime.Now
    SetupObject(thePos)
End Sub



that gets initialised with sub a a couple of times. So sub A gets called x amount of times.
This creates new instances and they all work autonomously and seperate from eachother.
That part works great.

The thing is when the instance becomes obsolete it knows it and need to be destroyed... ended deinitialised or whatever
I dont keep theGauge class variable anywhere (or i would rather not as there is no point)

So can the class instance dinitialize itself when needed from within itself like (me.finish)?

thx for even reading this :)
 
Last edited:

Marc De Loose

Member
Licensed User
Longtime User
After some thought is this not enough? (the simple Return statement)

B4X:
Public Sub Tick (GS As X2GameStep)
    If GS.ShouldDraw Then
        If DragMode=False Then
            setRPMledsv2
        End If
    end if
    if myWorkIsDone then
            Return
    end if
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You posted a general question about classes. The answer is that you don't need to do anything special. The class instance will be released once there are no live references to that instance.

If you have a specific question about a class instance usage in XUI2D then it is better to post in the game forum and provide more information about the class.
 
Upvote 0
Top