Skip to content

On ARC platforms, replace [weak] with [unsafe] where appropriate. #210

@rlebeau

Description

@rlebeau

In several strategic places throughout Indy, the [weak] attribute is used for various object references on ARC platforms. In some of these cases, the [unsafe] attribute might make more sense to use, as letting the RTL automatically track and nil these references when the referenced objects are destroyed is not always necessary or desirable.

Maybe just replace all uses of [weak] with [unsafe]? On ARC platforms, [weak] object referencing is not implemented very efficiently in Delphi (yet?), so there are performance overheads, and most places where [weak] is being used by Indy, TComponent.Notification() is also available, so [unsafe] would be a better choice in those cases to avoid unwanted overhead.

Even Embarcadero agrees that replacing [weak] with [unsafe] where appropriate can be used is beneficial:

https://quality.embarcadero.com/browse/RSP-20087


Note: [unsafe] is available for ARC platforms only in Delphi 10.1 Berlin and later. For earlier versions, perhaps use raw pointer references instead?


Update: Embarcadero is removing TObject ARC memory management from all compilers in RAD Studio 10.4, so this will only be an issue for Delphi 10.1 Berlin, 10.2 Tokyo, and 10.3 Rio:

https://community.idera.com/developer-tools/b/blog/posts/get-ready-for-the-10-4-beta-with-update-subscription

Metadata

Metadata

Assignees

Labels

Element: Compiler/IDEIssues related to a particular Compiler and/or IDEStatus: Review NeededIssue needs further review to decide next statusType: EnhancementIssue is proposing a new feature/enhancement

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions