SourceForge.net Construction and Destruction

Construction and Destruction
Table of Contents

Initializing and destroying objects


Constructors can be created by making a method with the same name as the class. You can create multiple constructors, as long as they take different numbers or types of parameters.

There is no inherent need for destructors, since Euphoria automatically garbage collects normal Euphoria data. You can make a custom method to handle any necessary cleanup, but it must be manually called.

    euclass Something( atom x )
        function Something()
        -- ignore the this variable...
            return allocate(4)
        end function

        procedure destroy()
            free(this)
        end procedure
    end euclass

    Something s
    s = Something.create(0) -- note that this argument must pass typechecking!