in this example
procedure foobar;
var tab:array of integer;
begin
setlength(tab,10);
end;
is the array destroyed or the memory is leaking?
For dynamically allocated memory like “int *p = new int[10]”, it is programmers responsibility to deallocate memory when no longer needed. If programmer doesn't deallocate memory, it causes memory leak (memory is not deallocated until program terminates).
If you don't delete them, they will remain there (but won't be accessible -> this is called memory leak) until your process exits, when the operating system will deallocate them. Save this answer.
The right syntax for a dynamic array is int* arr = new int[5]; . Yes, it will be allocated contiguously.
The memory is freed. (That is, no memory leak!)
The array is automatically freed, but I've seen obscure cases where it isn't for some reason. I solved it by setting the array to nil.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With