Repository navigation
Operator Delete Statement
Home › Operators › Operator Delete Statement
Operator to destroy data and free memory allocated with the Operator New Expression
buf
The Delete Statement operator is used to destroy and free the memory of an object created with New Expression operator. When deleting a TYPE, its destructor will be called. Delete Statement operator should only be used with addresses returned from New Expression operator.
The array version of Delete Statement operator, Delete[] Statement operator, is used to destroy an array of objects previously created with New[] Expression operator, the array-version of New Expression operator. Destructors will be called here as well.
Delete Statement operator must be used with addresses returned from New Expression operator, and Delete[] Statement operator with New[] Expression operator, the array-version of New Expression operator. You cannot mix and match the different versions of the operators.
After the memory is deleted, the buf pointer will be pointing at invalid memory. Calling Delete Expression twice on the same pointer value leads to undefined behavior. It may be a good idea to set the buf pointer to null (0), in order to guard against later code using it accidentally, since null pointer dereferences are easier to find and debug.
Calling Delete Statement operator on a null pointer induces no action.
The memory deallocation process part provided by the Delete Statement operator can be overloaded for user-defined types as a member operator Delete Overload. The previous process part for data destruction can never be modified.
Note: Any operator Delete[] (Statement or Overload) and the only Overload operator Delete are not compatible with sub-type polymorphism, even using Override Virtual Destructor that may in addition induce crashing.
Instead of having to call such an operator Delete([]) Statement on derived-type pointer, the safest way is to simply call (on base-type pointer) an overridden user Virtual member procedure that will automatically launch the operator Delete([]) Statement at derived-type level.
Delete buf
or
Delete[] buf- Only available in the -lang fb dialect.
- New to FreeBASIC
Type Rational
As Integer numerator, denominator
End Type
' Create and initialize a Rational, and store its address.
Dim p As Rational Ptr = New Rational(3, 4)
Print p->numerator & "/" & p->denominator
' Destroy the rational and give its memory back to the system.
Delete p
' Set the pointer to null to guard against future accesses
p = 0' Allocate memory for 100 integers, store the address of the first one.
Dim p As Integer Ptr = New Integer[100]
' Assign some values to the integers in the array.
For i As Integer = 0 To 99
p[i] = i
Next
' Free the entire integer array.
Delete[] p
' Set the pointer to null to guard against future accesses
p = 0Category: Operators
Kind: operator
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