This makes it one of the few modern languages where you have to manually free all child pointers (like in C).
This makes it one of the few modern languages where you have to manually free all child pointers (like in C).
The first way to auto destroy objects is to expose an Interface and free your object in the Release method. You can inherit from several class types that already do that if you don't want to rewrite a new class.
The second way is a newer feature that allows you to define Initiazlize and Finalize methods on any complex type. When you define these methods, the compiler generates code to reference count your object and call Initazlize on create, and Finalize when your object is no longer referenced. This works the same on stack based types as well as heap allocated types.
Do you think that the changes help with simpler algorithms -- like in StringHashList [0], where destructor specifically calls Dispose on each array element, and then deletes the array storage itself?
[0] https://github.com/graemeg/lazarus/blob/95d183bacd5f895d3e6c...
The change we're talking about automatically invokes Initialize and Finalize on all types for dynamic allocations / destruction, unless they intentionally circumvent it. Intentional circumvention might include allocating raw memory in a class and treating the class like an array with an index property. In other words, if you declare a raw pointer, allocate untyped memory (e.g. bytes), and handle something back from that memory using a typecast, then you are bypassing automatic allocation and destruction.
All other ways to make space for complex types (records and classes) as well as types which may hold complex types (arrays and nested fields) will safely and reliably use Initialize and Finalize when needed if they are defined.
Or use fpcupdeluxe with several clicks, screenshot here: https://screenpresso.com/=iyqoc