The TAutoFree class is a minimalist part of another repository of mine that provides the same functionality. https://github.com/daviladanielc/Delphi-Garbage-Collector
It is an attempt at automating the process of releasing objects in Delphi without the need to use Try Finally blocks to free objects after their usage.
The idea behind this project is not to require the programmer to migrate their classes to an interface and to improve memory management. With the TAutoFree class, it's possible to turn a simple class into something like a interface without implementing anything new.
Add the folder where uClassAutoFree.pas is located to the Delphi library path or to your project's search path.
If you believe you can help improve this repository, please submit a PR, and I will review it. Any assistance is welcome.
- Tested in Delphi 11.0
I recommend using Delphi XE or better.
Example of how to use the TAutoFree class
uses uClassAutoFree
var
LLocal: TMyClass;
begin
LLocal:= TAutoFree<TMyClass>.New(TMyClass.Create).GetInstance;
LLocal.FParam:= 'test';
Showmessage(LLocal.FParam);
//LLocal its destroyed here
end;
