Search code examples
.netdata-structuresrecordnulldelphi-prism

How to delete or destruct an instance of a data structure or a record?


I have a data structure as follows.

TJustCalGroup = record
    SigName,GroupName:string;
    RawMin,RawMax:LongInt;
end;

I create an instance of the record or data structure as follows.

var ARecord := new TJustCalGroup;

Then, I want to delete the instance or mark it as being unused. So, I am doing the following.

ARecord := Nil;

However, it is not working. It keeps raising an error, "Can not assign nil to TJustCalGroup."

So, then how do you make it nil or null or free up its memory?


Solution

  • A delphi prism (or Oxygene)record is equivalent to a Struct , the structs (or records) are value types and is allocated always on the stack (even when you uses the new operator), so you don't need free the memory.