Repository navigation
Destructor
Home › User Defined Types › Destructor
Called automatically when a class or user defined type goes out of scope or is destroyed
Type typename
field declarations
Declare Destructor ( )
End Type
Destructor typename ( ) [ Export ]
statements
End Destructortypename
The destructor method is called when a user defined Type or Class variable goes out of scope or is destroyed explicitly with the Delete Statement operator.
typename is the name of the type for which the Destructor method is declared and defined. Name resolution for typename follows the same rules as procedures when used in a Namespace.
The Destructor method is passed a hidden This parameter having the same type as typename.
The destructor in a type is called before the destructors on any of its fields. Therefore, all fields are accessible with the hidden This parameter in the destructor body.
Only one destructor may be declared and defined per type (but several destructors can be called in a chained way if the type contains or inherits other types with their own destructors).
Since the End statement does not close any scope, object destructors will not automatically be called if the End statement is used to terminate the program.
Destructor can be also called directly from the typename instance like the other member methods (Sub) and with the same syntax, i.e. using a member access operator, e.g. obj.Destructor(). The object, and all its members, are assumed to be constructed and in a valid state, otherwise its effects are undefined and may cause crashes. This syntax is useful in cases where obj has been constructed manually, e.g. with obj.Constructor() or Placement New.
- Object-related features are supported only in the -lang fb dialect.
- New to FreeBASIC
Type T
value As ZString * 32
Declare Constructor ( init_value As String )
Declare Destructor ()
End Type
Constructor T ( init_value As String )
value = init_value
Print "Creating: "; value
End Constructor
Destructor T ()
Print "Destroying: "; value
End Destructor
Sub MySub
Dim x As T = ("A.x")
End Sub
Dim x As T = ("main.x")
Scope
Dim x As T = ("main.scope.x")
End Scope
MySubOutput:
Creating: main.x
Creating: main.scope.x
Destroying: main.scope.x
Creating: A.x
Destroying: A.x
Destroying: main.xCategory: User Defined Types
Kind: type
Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing