delphirecord

Do string variables in records get freed when the record goes out of scope?


In Delphi you can declare a record containing a String. This means the record just contains a pointer the heap when the string is located; does the heap memory get freed when this record goes out of scope? Where would I find a documentation on such behavior?


Solution

  • Yes, strings are reference counted and the heap objects are freed when the reference count reaches zero, which happens when the last reference to the string goes out of scope. This includes references that are object and record members.