Android Question end class instance (from within)

Discussion in 'Android Questions' started by Marc De Loose, Feb 12, 2019.

  1. Marc De Loose

    Marc De Loose Member Licensed User

    lets say i have a sub in main
    Code:
    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
    Code:
    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: Feb 12, 2019
  2. LucaMs

    LucaMs Expert Licensed User

  3. Marc De Loose

    Marc De Loose Member Licensed User

    After some thought is this not enough? (the simple Return statement)

    Code:
    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
     
  4. Erel

    Erel Administrator Staff Member Licensed 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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice