Hi there,
let's assume you have a large record.
ExampleRecord = record
entry1: Integer;
entry2: AnotherRecord;
entry3: array[0..1024] of Boolean;
.
.
end;
Well, in case of making the ExampleRecord part of a dyn. array, it would be completly pushed into the heap (is that true?). Let's assume I just need one instance of this record, it would be stored in the stack.
If it is a global record, YES, heap, if it is local to a procedure or function, NO, stack!
What can I do now to get it pushed to the heap?
It isn't!
If I do this
what follows for the elements of the array or the fields of AnotherRecord? Are the elements and the fields on the heap, too?
You completely misunderstand what's happening. But IF it is a global record or a local pointer to record then yes.. it is on the heap. But if it is declared on the stack the members are also on the stack, unless declared as a pointer to record and new(0 and Dispose() Then it is on the heap. (And inaccessible when declared as local and you forgot to call dispose: memory leak).
When you use the record locally (not the pointer) it will be free'd automatically because it is on the stack (in full) if you use new() and Dispose() locally only the pointer disappears from the stack and you have a memory leak if you do not call dispose.
Note if your record contains members of a managed type, these are always on the heap (Like AnsiStrings, classes and interfaces). Even if the record is on the stack.