Was curious if Chat GPT would be able to find the problem if I told it that there was a memory leak which it was able to find.<p><a href="https://chatgpt.com/share/70af56e3-2fde-4dab-8b59-d05960dadd56" rel="nofollow">https://chatgpt.com/share/70af56e3-2fde-4dab-8b59-d05960dadd...</a><p>Just asking if there's a problem and asking Chat GPT to rank the error leads the memory leak error to be categorized as low criticality though.<p><a href="https://chatgpt.com/share/68eb706a-05eb-44ca-8e2b-abc97c04227d" rel="nofollow">https://chatgpt.com/share/68eb706a-05eb-44ca-8e2b-abc97c0422...</a><p>Pretty promising though that it was able to point out the problem even without pointing it out and it definitely caught the memory leak issue.<p>Claude 3.5 Sonnet was able to figure it out right away without pointing it out though.
Most languages have a rule of thumb when it comes to freeing resources; it is your responsibility to abide by them.<p><pre><code> Rust: drop
C++: T::~T()
C#: using + dispose
Java: try-with + autocloseable, or finally
Go: defer
Haskell: bracket
JavaScript: finally
Python: finally or with + __exit__
</code></pre>
Don't like it? Vote for linear types.
For a piece of code like this, it's too bad there is not a relatively easy conversion possible to an arena-based allocator. Because then the leak would not be relevant.<p>I wonder if it would be possible in Rust to do some magic at the Rust/C border in order to trick old C code into living inside an arena that is invisible to it?
Tangentially.. this is one of the things I don't like about a lot "newer" languages, like Rust and Zig. They seem to really love adding these single character sigils to the language that drastically change the meaning of a line of code or maybe an entire function.<p>As I get older my eyes strain more and all of this power packed into a single character really just puts me off. It seems like a strategy to emphasize writing code quickly rather than correctly, which is odd, given that this is opposite to the value proposition these languages purport to bring.