Solved

Freeing components

Posted on 1998-03-20
3
148 Views
Last Modified: 2010-04-06
Do I have to close free all objects created with Free
before terminating application, or all of them are
automatically free-ed?
0
Comment
Question by:bor061297
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 2

Accepted Solution

by:
mvz121697 earned 50 total points
ID: 1360664
As a general rule:
Free all components which you are creating yourself,
with the Create-method.
So if you are dropping components on your form, don't worry about freeing, Delphi does it for you.

But if you are creating components dynamicly, you have to free them, like this:

var fm:TForm;
begin
fm:=TForm.create(Self);
try
  // stuff...
   fm.ShowModal;
finally  
  fm.Free;
end;


BTW, if you don't follow this rule for VCL-components,
they will still automaticly be freed, when the parent is destroyed. (The parent is the object you supply as a parameter in the create-method).  
You can also let the Application be the parent, like this:

fm:=TForm.Create(Application)

If you don't free this yourself, it will be freed when the application ends.


Greetings,
MvZ




0
 
LVL 4

Expert Comment

by:d003303
ID: 1360665
just a little cosmetics, the owner is passed in the Create method. Also, if the owner is freed, all owned components are freed, too. This does not depend on the parent property.
Generally, all components on a form are owned by the form. If e.g. a label resists on a panel wich resists on a form, the owner property of all two components is the form. The parent of the label though is the panel, the parent of the panel is the form. And normally all forms are owned by the application and have no parents (except MDIChild wich has the MDIForm as a parent).

Slash/d003303
0
 

Author Comment

by:bor061297
ID: 1360666
If I create a BitMap with:

Bitmap := TBitMap.Create;

is it automatically freed when application ends?
And, who owns Bitmap created in this way
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Tvertscrollbox like a whatsapp layout delete messages 1 50
Firemonkey BASS_Init into a thread 17 79
Delphi Seattle StructureView color 1 33
TAction.OnAfterExecute? 2 31
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question