Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are managed types? Are they specific to Delphi? Are they specific to Windows?

Summarization:

Please check the knowledgeable comments below.

==============================================================

I have seen the term of managed types mentioned in quite a few stackoverflow Delphi topics. For example, it is mentioned in topics of correctly initializing/finalizing. However, when I google managed types, it seems most links are related to C++, or .NET. For example, see the MSDN page. Could some one help to comment what are managed types defined in Delphi? Given that Delphi for POSIX/MacOS is being born, are managed types specific to Windows? Thanks for your effort and time in advance!

PS: Topics of correctly initializing/finalizing:
Which variables are initialized when in Delphi?
Are delphi variables initialized with a value by default?
How should I free an array of objects in a Delphi 7 destructor?
In Delphi 2009 do I need to free variant arrays?

like image 617
SOUser Avatar asked Mar 18 '11 11:03

SOUser


2 Answers

In the context of Delphi, managed types are those types for whom the Delphi Compiler automatically generates lifecycle management code. This includes:

  • Strings
  • Open Dynamic Arrays
  • Records containing other managed types
  • Interfaces
  • (later edit) Anonymous methods
  • (later edit) Variants

Because managed types in the Delphi context are defined in terms of what the Delphi compiler generates, they're delphi-specific.


In the .NET world the developer doesn't need to manage the lifecycle of allocated memory because .NET provides an automatic mechanism for doing this: The Garbage Collector. But .NET includes the ability to work with things outside the CLR (example: using native DLL's that don't target the CLR). That code is usually called unamanged and unsafe.

In the context of .NET managed relates to what the CLR automatically manages, so that's .NET specific term!

like image 130
Cosmin Prund Avatar answered Nov 03 '22 12:11

Cosmin Prund


See Barry Kelly's answer to a releated thread. Since managed types are a language feature there shouldn't be significant changes on Mac OS et al.

like image 2
Uli Gerhardt Avatar answered Nov 03 '22 14:11

Uli Gerhardt