SmartPointers
This repo includes all different versions of SmartPointer in Delphi to simulate a garbage collector.
Install / Use
/learn @AliDehbansiahkarbon/SmartPointersREADME
SmartPointers (Garbage collector simulator) for Delphi.
This repo includes 7 different implementations of SmartPointers in Delphi to simulate a simple garbage collector.
In this way you will bind your objects to a reference counting supported object like an interface or a record and this object will automatically free the referenced object at the end of the scope. You just create your object and don't worry about freeing anymore.
There is a sample vcl app to demonstrate the usage.
Simple Usage
presumptive class
TPerson = class
FName: string;
FAge: Integer;
public
constructor Create; reintroduce; overload;
constructor Create(const AName: string; const AAge: Integer); reintroduce; overload;
destructor Destroy; override;
procedure Birthday;
property Name: string read FName write FName;
property Age: integer read FAge write FAge;
end;
Version 1, 2, 3, 4 (usages are same but different implementations)
var Person1: ISmartPointer1{or 2-4}<TPerson> := TSmartPointer1{or 2-4}<TPerson>.Create(TPerson.Create('Alex', 50));
Person1.Ref.Birthday; // use the created object
//done, no need to free the object.
Version 5
var
LvPerson1: ISmartPointer5<TPerson>;
begin
LvPerson1 := TSmartPointer5<TPerson>.Create(TPerson.Create('Person1', 45));
LvPerson1.Birthday; // direct member access, do something with object.
// done, no need to free.
end;
Version 6
var
LvPerson1: TPerson;
begin
LvPerson1 := SmartPointer6<TPerson>(TPerson.Create('Ali', 25));
LvPerson1.Birthday;// do anything
//done, no need to free.
end;
Version 7
var
x: TSmartPointer7<TLifetimeWatcher>;
begin
x := TLifetimeWatcher.Create(procedure begin ShowMessage('Destroying...'); end); // pass anonymouse method just for watching the life cycle of the object(it's not mandatory.)
ShowMessage(X.Value.Birthday); // use the object.
//done, noe need to free
end;
<hr>
<p align="center">
<img src="https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2022/11/dlogonew-5582740.png?resize=254%2C242&ssl=1" alt="Delphi">
</p>
<h5 align="center">
Made with :heart: on Delphi
</h5>Related Skills
node-connect
351.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
110.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
351.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
351.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
