Components and Ownership

From RAD Studio
Jump to: navigation, search

Go Up to Creating, Instantiating, and Destroying Objects


Delphi components have a built-in memory-management mechanism that allows one component to assume responsibility for freeing another. The former component is said to own the latter. The memory for an owned component is automatically freed when its owner's memory is freed. The owner of a component - the value of its Owner property - is determined by a parameter passed to the constructor when the component is created. By default, a form owns all components on it and is in turn owned by the application. Thus, when the application shuts down, the memory for all forms and the components on them is freed.

Ownership applies only to TComponent and its descendants. If you create, for example, a TStringList or TCollection object (even if it is associated with a form), you are responsible for freeing the object.

See Also