Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Delphi 2009 do I need to free variant arrays?

If I have a variant array which holds nothing but simple types, and possible further variant arrays of simple types, do I need to do anything explicit to free memory, or is it all taken care of for me. I've always thought there is nothing to do, but I just had a slight doubt!

like image 487
Steve Avatar asked May 22 '09 11:05

Steve


People also ask

What is a variant in Delphi?

The Variant type is a dynamic type. A Variant variable can change type at runtime, sometimes storing an integer, other times a string, and other times an array. Delphi automatically casts numbers, strings, interfaces, and other types to and from Variant s as needed.


1 Answers

Variants are managed types. They're owned by the compiler's reference-counting system and don't need to be freed manually.

If you do something convoluted like typecasting an object to an integer and storing that in the variant, and then making that the only reference to your object, then you'll want to clean that up before the variant goes out of scope, but the variant itself (including variant arrays) is safe.

like image 142
Mason Wheeler Avatar answered Nov 09 '22 06:11

Mason Wheeler