If some variable is pointing to some block of memory somewhere, what value is assigned to that variable when the memory block is freed ? or the fact that it is non nil-able means the block of memory can never be freed (except by the O/S when the app ends) ? Additionally, before the address of a dynamically allocated block of memory was assigned to it, what value did it have if it couldn't be nil ?
How does Dart deal with those situations ? (I watched the video and read the intro to the language in the web site but... obviously that is quite insufficient to have a reasonable grasp on the language.)
Dart has GC, no memory management.
"Sound Null Safety" is separate from memory management.
When a non-nullable variable is declared without initialization it must be annotated with "
late" modifier and internally it is inited to null(hidden), and at each usage of that var in function body compiler inserts a run-time null-check that raises exception if var is null. Modifier "late" means - verify at run-time.
Compiler advises at the point of usage of such "late" variable that it may raise an exception if you forgot to initialize it - "you better wrap it in TRY block".
In FPC a variable may become a dangling reference even though not NIL, it's a possible "
use after free" error. As usual in Object Pascal code.
"Sound Null Safety" is not about memory management.
Seems to me there's got to be a way to coerce a non nil-able variable into being nil and once that is done then it has all the problems associated with nil variables (particularly if the compiler believes its value cannot be nil.)
In Dart, no.
FPC has VAR parameters.
Declarations like this with typeless VAR parameter:
FreeAndNil(var obj);There could be special case for "?" without type:
FreeAndNil(var obj?); , and compiler must not accept non-NILable argument for such VAR parameter.