15 ms·
Manual memory management is the weak point of Pascal. It limits functions to never returning newly constructed objects, which really limits the expressiveness o
by johnthuss 10y ago
Manual memory management is the weak point of Pascal. It limits functions to never returning newly constructed objects, which really limits the expressiveness of APIs both in the standard library and in custom code.
The manual reference counting system in old objective-c provides a better solution which while still cumbersome, doesn't prevent good powerful APIs.
The automatic reference counting capability of Delphi interfaces always seemed like a good idea to me, but seems to be rarely used.
- deleted 10y ago[deleted]
- clouddrover 10y ago> It limits functions to never returning newly constructed objects, which really limits the expressiveness of APIs both in the standard library and in custom code. How? Set the return type of the function to be the object type you want, then result := TYourObjectType.Create; and you'll return a newly constructed object.
- badsectoracula 10y agoNote that Free Pascal does have automatic reference counting for interfaces, although it is not a good idea to use it for memory management because (like with Delphi) it is very easy to pass around an instance that isn't counted and end with memory leaks. However one of the compiler's designers has an experimental branch which allows you to mark classes as being automatically managed and any instance and use of those classes becomes reference counted. So at some point it might become part of the main compiler (although it is probably far from now since AFAIK it isn't something people really ask for from FPC and there are other things to do).
- revanx_ 10y agoIt limits functions to never returning newly constructed objects No it doesn't. The automatic reference counting capability of Delphi interfaces always seemed like a good idea to me, but seems to be rarely used. You mean rarely used by people who are amatures, developers have always been pushed towards programming against interfaces.