<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Hairy Pixels via fpc-pascal <<a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>> schrieb am Fr., 18. Okt. 2024, 17:21:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Oct 18, 2024 at 3:41:49 PM, Karoly Balogh via fpc-pascal <<a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank" rel="noreferrer">fpc-pascal@lists.freepascal.org</a>> wrote:<br></div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" type="cite">
Maybe it was mentioned in the thread, I just glanced through it, but how<br>about ARC (Automatic Reference Counting), Objective C style? To be honest,<br>I really liked that, and we already have it kind of in place for strings,<br>even temporary strings and maybe even temporary arrays created inside a<br>function. We'd just need to extend it for a bunch of other things, I<br>suppose. Manual FreeAndNil() is the ugliest part of Object Pascal for me<br>for sure... OTOH, for Object Pascal you might end up with RAII in this<br>case, instead of ARC, because how how the language works. I did not like<br>it that much in C++, but maybe because modern C++ syntax is properly<br>horrid...<br>
</blockquote>
</div>
<br>
<div dir="ltr">The compiler already has all the plumbing for implementing this but they would need to agree to a new class type which includes has the same ref counting as AnsiString, Interfaces and other types. I mentioned this multiple times but Sven objected to it stating he already tried and uncounted some edge cases.</div><div dir="ltr"><br></div><div dir="ltr">I think an entirely new class type would be required and that’s where the resistance came from. Sven can refresh us on this if he wants.</div></div></blockquote></div></div><div dir="auto"><br></div><div dir="auto">The problem is that we can't simply introduce reference counting for existing classes, because that would lead to memory leaks in existing codes, because that might have cyclic references. </div><div dir="auto"><br></div><div dir="auto">This would mean that a new class type or some kind of additional attribute would have to be introduced which would have to be incompatible to non-reference-counted classes as otherwise there would be the chance for memory leaks or use-after-free again. This in turn would mean that essenentially the whole class hierarchy would have to be reimplemented. </div><div dir="auto"><br></div><div dir="auto">And that whole shebang is just not worth it. If someone wants a full ARC language then simply don't use Object Pascal. </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>