6

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?

Community
  • 1
  • 1
SOUser
  • 3,802
  • 5
  • 33
  • 63

2 Answers2

8

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!

Cosmin Prund
  • 25,498
  • 2
  • 60
  • 104
  • @Cosmin: Thank you for your help! You mention four kinds of managed types. Is your list exclusive? I mean, is your list `the` list of managed types in Delphi? (And thanks for your helpful comments on .NET managed types.) – SOUser Mar 18 '11 at 11:56
  • 1
    No, it's not exclusive. I'm introducing the list with `this includes`. Right now I can't think of any other, but I can't vouch that's the complete list. – Cosmin Prund Mar 18 '11 at 11:59
  • @Cosmin: I see! Then I guess there does not exist a complete list of managed types for Delphi actually? – SOUser Mar 18 '11 at 12:02
  • 2
    @Xichen Li, there's definitively a list: the compiler knows precisely what types are managed and what types are not. Maybe someone at Embarcadero can tell us the exact list. Or someone with better googling skills. – Cosmin Prund Mar 18 '11 at 12:06
  • 1
    Is `Open Arrays` the correct terminology? I thought the managed ones are called dynamic arrays, and open arrays are just a parameter passing technique. – CodesInChaos Mar 18 '11 at 12:11
  • @Cosmin: Thanks! I will then wait a while for `the` list. :D – SOUser Mar 18 '11 at 12:16
  • 1
    As far as the documentation is concerned the list is: [(Memory Management on the Win32 Platform)](http://docwiki.embarcadero.com/RADStudio/en/Memory_Management_on_the_Win32_Platform) *"Long strings, wide strings, dynamic arrays, variants, and interfaces are heap-allocated, but their memory is managed automatically."*. But, as it leaves out method references, I guess we can't count on it. – Sertac Akyuz Mar 18 '11 at 15:03
  • @Sertac: Thanks very much for the information! It looks as official as it can be! – SOUser Mar 18 '11 at 17:14
  • Update: In the latest Delphi there are can now be interfaces which are not managed; there are both [unsafe] and [weak] annotations which alter the way the compiler manages interfaces (and the associated reference counting) – AdrianGW Oct 09 '16 at 04:49
2

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.

Community
  • 1
  • 1
Uli Gerhardt
  • 13,748
  • 1
  • 45
  • 83
  • Thank you for your help! Barry mentioned a list of example of managed types. Nonetheless, is that list exclusive? – SOUser Mar 18 '11 at 11:55
  • 3
    That list might have been comprehensive when Barry wrote it, but it's missing anonymous methods which were added later. – David Heffernan Mar 18 '11 at 12:28