Garbage collection doesn’t guarantee memory safety and it’s perfectly possible to create a memory-safe language without garbage collection. There are plenty of garbage collectors for C++ (and until C++23, support for garbage collection was part of the standard, although no one implemented it), and languages like C# let you interact with garbage-collected objects in unsafe blocks.
Exactly, if garbage collection meant memory safety then why do we get null pointer exceptions about every 5 minutes in Java. Garbage collection is about memory leaks, not safety. Imho the borrow checker is a better solution than garbage collection and faster to boot.
Null safety and memory safety are different features.
Null safety means that you cannot access a struct’s fields without first checking if the pointer to that struct isn’t null. And this must be a compile-time check.
Memory safety means that you cannot read or write to/from memory that has been free-ed. Without leaks ofc, otherwise it would be very easy.
Garbage collection doesn’t guarantee memory safety and it’s perfectly possible to create a memory-safe language without garbage collection. There are plenty of garbage collectors for C++ (and until C++23, support for garbage collection was part of the standard, although no one implemented it), and languages like C# let you interact with garbage-collected objects in
unsafe
blocks.Exactly, if garbage collection meant memory safety then why do we get null pointer exceptions about every 5 minutes in Java. Garbage collection is about memory leaks, not safety. Imho the borrow checker is a better solution than garbage collection and faster to boot.
Null safety and memory safety are different features.
Null safety means that you cannot access a struct’s fields without first checking if the pointer to that struct isn’t null. And this must be a compile-time check.
Memory safety means that you cannot read or write to/from memory that has been free-ed. Without leaks ofc, otherwise it would be very easy.