Solved

Freeing components

Posted on 1998-03-20
3
138 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Simple Delphi Question 9 83
Process Javascript errors with Delphi TWebBrowser 1 111
how to center only a line in richedit? 4 52
Delphi selector screen 2 69
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

914 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now