type
TSomeRecord = Record
field1: integer;
field2: string;
field3: boolean;
End;
var
SomeRecord: TSomeRecord;
SomeRecAr: array of TSomeRecord;
This is the most basic example of what I have and since I want to reuse SomeRecord
(with certain fields remaining empty, without freeing everything some fields would be carried over when I'm reusing SomeRecord
, which is obviously undesired) I am looking for a way to free all of the fields at once. I've started out with string[255]
and used ZeroMemory()
, which was fine until it started leaking memory, that was because I switched to string
. I still lack the knowledge to get why, but it appears to be related to it being dynamic. I am using dynamic arrays as well, so I assume that trying ZeroMemory()
on anything dynamic would result in leaks. One day wasted figuring that out. I think I solved this by using Finalize()
on SomeRecord
or SomeRecAr
before ZeroMemory()
, but I'm not sure if this is the proper approach or just me being stupid.
So the question is: how to free everything at once? does some single procedure exist at all for this that I'm not aware of?
On a different note, alternatively I would be open to suggestions how to implement these records differently to begin with, so I don't need to make complicated attempts at freeing stuff. I've looked into creating records with New()
and then getting rid of it Dispose()
, but I have no idea what it means when a variable after a call to Dispose()
is undefined, instead of nil. In addition, I don't know what's the difference between a variable of a certain type (SomeRecord: TSomeRecord
) versus a variable pointing to a type (SomeRecord: ^TSomeRecord
). I'm looking into the above issues at the moment, unless someone can explain it quickly, it might take some time.