Delphi / FireMonkey release components created at runtime [Edit]

Hello,

XE6, Win7

Am I right I thinking that if I create a component, such as TImage, at runtime, Delphi automatically releases the memory when the program closes.

I declared this:

  im: TImage;

as a TForm variable.

Put this in .FormCreate:

  ReportMemoryLeaksOnShutdown := DebugHook <> 0;

This picks up things like TStrokeBrush when I don't run .Free;

I then put this in:

procedure TFrmScales.Button4Click(Sender: TObject);
begin
  im := TImage.Create(self);
  im.Bitmap.Assign(I_note.Bitmap);  // I_note is a TImage that I put there at design-time
  im.Parent := self;
  im.Position.X := 10;
  im.Position.Y := 10;
end;

If I don't run im.Free there is no memory leak reported.

So, it looks like Delphi cleans up visual components that are created at runtime - is this correct?

Many thanks,

Ian

Edited by: Ian Johnson on Jul 14, 2014 8:58 PM
0
Ian
7/15/2014 4:06:17 AM
embarcadero.delphi.firemonkey 4901 articles. 4 followers. Follow

3 Replies
1516 Views

Similar Articles

[PageSpeed] 0

Ian Johnson wrote:
> Hello,
> 
> XE6, Win7
> 
> Am I right I thinking that if I create a component, such as TImage, at runtime, Delphi automatically releases the memory when the program closes.

Under the mobile compilers, yes since the ref count will go to 0 and the memory 
released by ARC.  In desktop no, but the OS will claim all memory when an app 
closes so it is not really a big deal.  Still good practice to cleanup after 
yourself, but sometimes if the cleanup takes time you can just let the OS 
reclaim the whole heap blocks.

> 
> I declared this:
> 
>   im: TImage;
> 
> as a TForm variable.
> 
> Put this in .FormCreate:
> 
>   ReportMemoryLeaksOnShutdown := DebugHook <> 0;
> 
> This picks up things like TStrokeBrush when I don't run .Free;
> 
> I then put this in:
> 
> procedure TFrmScales.Button4Click(Sender: TObject);
> begin
>   im := TImage.Create(self);
>   im.Bitmap.Assign(I_note.Bitmap);  // I_note is a TImage that I put there at design-time
>   im.Parent := self;
>   im.Position.X := 10;
>   im.Position.Y := 10;
> end;
> 
> If I don't run im.Free there is no memory leak reported.
> 
> So, it looks like Delphi cleans up visual components that are created at runtime - is this correct?
> 
> Many thanks,
> 
> Ian
> 
> Edited by: Ian Johnson on Jul 14, 2014 8:58 PM

In your example code the component is owned by the form so when the form is 
destroyed it frees all things it owns.  The TImage will also free all its 
resources when the form frees it.

In this case mobile and desktop should behave essentially the same way as the 
owner will be responsible for freeing/niling the references to the object 
resulting in the memory being released.

-- 
Jeff Overcash (TeamB)
       (Please do not email me directly unless  asked. Thank You)
And so I patrol in the valley of the shadow of the tricolor
I must fear evil. For I am but mortal and mortals can only die.
Asking questions, pleading answers from the nameless
faceless watchers that stalk the carpeted  corridors of Whitehall.
              (Fish)
0
Jeff
7/15/2014 4:36:32 AM
> {quote:title=Jeff Overcash (TeamB) wrote:}{quote}
> Ian Johnson wrote:
> > Hello,
> > 
> > XE6, Win7
> > 
> > Am I right I thinking that if I create a component, such as TImage, at runtime, Delphi automatically releases the memory when the program closes.
> 
> Under the mobile compilers, yes since the ref count will go to 0 and the memory 
> released by ARC.  In desktop no, but the OS will claim all memory when an app 
> closes so it is not really a big deal.  Still good practice to cleanup after 
> yourself, but sometimes if the cleanup takes time you can just let the OS 
> reclaim the whole heap blocks.
> 
> > 
> > I declared this:
> > 
> >   im: TImage;
> > 
> > as a TForm variable.
> > 
> > Put this in .FormCreate:
> > 
> >   ReportMemoryLeaksOnShutdown := DebugHook <> 0;
> > 
> > This picks up things like TStrokeBrush when I don't run .Free;
> > 
> > I then put this in:
> > 
> > procedure TFrmScales.Button4Click(Sender: TObject);
> > begin
> >   im := TImage.Create(self);
> >   im.Bitmap.Assign(I_note.Bitmap);  // I_note is a TImage that I put there at design-time
> >   im.Parent := self;
> >   im.Position.X := 10;
> >   im.Position.Y := 10;
> > end;
> > 
> > If I don't run im.Free there is no memory leak reported.
> > 
> > So, it looks like Delphi cleans up visual components that are created at runtime - is this correct?
> > 
> > Many thanks,
> > 
> > Ian
> > 
> > Edited by: Ian Johnson on Jul 14, 2014 8:58 PM
> 
> In your example code the component is owned by the form so when the form is 
> destroyed it frees all things it owns.  The TImage will also free all its 
> resources when the form frees it.
> 
> In this case mobile and desktop should behave essentially the same way as the 
> owner will be responsible for freeing/niling the references to the object 
> resulting in the memory being released.
> 
> -- 
> Jeff Overcash (TeamB)
>        (Please do not email me directly unless  asked. Thank You)
> And so I patrol in the valley of the shadow of the tricolor
> I must fear evil. For I am but mortal and mortals can only die.
> Asking questions, pleading answers from the nameless
> faceless watchers that stalk the carpeted  corridors of Whitehall.
>               (Fish)

Many thanks Jeff
0
Ian
7/15/2014 5:04:16 AM
> {quote:title=Jeff Overcash (TeamB) wrote:}{quote}
> Ian Johnson wrote:
> > Hello,
> > 
> > XE6, Win7
> > 
> > Am I right I thinking that if I create a component, such as TImage, at runtime, Delphi automatically releases the memory when the program closes.
> 
> Under the mobile compilers, yes since the ref count will go to 0 and the memory 
> released by ARC.  In desktop no, but the OS will claim all memory when an app 
> closes so it is not really a big deal.  Still good practice to cleanup after 
> yourself, but sometimes if the cleanup takes time you can just let the OS 
> reclaim the whole heap blocks.
> 
> > 
> > I declared this:
> > 
> >   im: TImage;
> > 
> > as a TForm variable.
> > 
> > Put this in .FormCreate:
> > 
> >   ReportMemoryLeaksOnShutdown := DebugHook <> 0;
> > 
> > This picks up things like TStrokeBrush when I don't run .Free;
> > 
> > I then put this in:
> > 
> > procedure TFrmScales.Button4Click(Sender: TObject);
> > begin
> >   im := TImage.Create(self);
> >   im.Bitmap.Assign(I_note.Bitmap);  // I_note is a TImage that I put there at design-time
> >   im.Parent := self;
> >   im.Position.X := 10;
> >   im.Position.Y := 10;
> > end;
> > 
> > If I don't run im.Free there is no memory leak reported.
> > 
> > So, it looks like Delphi cleans up visual components that are created at runtime - is this correct?
> > 
> > Many thanks,
> > 
> > Ian
> > 
> > Edited by: Ian Johnson on Jul 14, 2014 8:58 PM
> 
> In your example code the component is owned by the form so when the form is 
> destroyed it frees all things it owns.  The TImage will also free all its 
> resources when the form frees it.
> 
> In this case mobile and desktop should behave essentially the same way as the 
> owner will be responsible for freeing/niling the references to the object 
> resulting in the memory being released.
> 
> -- 
> Jeff Overcash (TeamB)
>        (Please do not email me directly unless  asked. Thank You)
> And so I patrol in the valley of the shadow of the tricolor
> I must fear evil. For I am but mortal and mortals can only die.
> Asking questions, pleading answers from the nameless
> faceless watchers that stalk the carpeted  corridors of Whitehall.
>               (Fish)

Hi Jeff - just posted a message to say thanks, and then thought of another related point! 

As far as I can work out, the only way I can close an application running on the iOS simulator is to terminate it from Delphi.  Even if I close it in the simulator, Delphi doesn't seem to know.  This means that I can't check for memory leaks as it hasn't closed properly.  That's why I'm testing it under Win32 but if the rules are different that could be tricky.  Is there a way of checking for leaks when it's running under the simulator?

Thanks, Ian
0
Ian
7/15/2014 5:16:08 AM
Reply:

Similar Artilces:

Ann: FastReport FMX for Delphi XE3 (FireMonkey 2) and XE2 (FireMonkey) released
Dear friends, Visual report designer is available now on both MS Windows and MAC OS X! Full sources. We can write here full list of possibilities, but it will so long. Let see FastReport VCL and FastReport FMX comparison table: http://www.fast-report.com/en/products/comparison-fast-report-firemonkey-vcl.html And all of this - just now in your hands for business-applications for Mac. Report generator FastReport FMX is the first multiplatform solution for including Business Intelligence into software based on Embarcadero FireMonkey IDE (Delphi for MS Windows and Apple Mac OS X)...

SEPA components for Delphi with Source Code (Delphi 5
Hi all, in the european union change next year the Bankingformat to the SEPA Format. All peoples and companies must change the bankingssoftware and the costumer data form acountnummers in the new IBAN and BIC numbers. See: http://www.arma-it.de/shop/artikelueber.php?wgruppeid=211&wgruppe_offen=211 Functions: - generate SEPA XML'S - Calc IBAN - BIC Database (DE,AT and CH) Questions: vertrieb@arma-it.de PS: Bankinssoftware for Develpoers (Germany only) http://www.arma-it.de/shop/artikelueber.php?wgruppeid=212&wgruppe_offen=212 El 26/10/13 21:38, A...

Ann: X-platform report generator for Delphi XE3 (FireMonkey 2) and XE2 (FireMonkey) released
Dear friends, Visual report designer is available now on both MS Windows and MAC OS X! Full sources. We can write here full list of possibilities, but it will so long. Let see FastReport VCL and FastReport FMX comparison table: http://www.fast-report.com/en/products/comparison-fast-report-firemonkey-vcl.html And all of this - just now in your hands for business-applications for Mac. Report generator FastReport FMX is the first multiplatform solution for including Business Intelligence into software based on Embarcadero FireMonkey IDE (Delphi for MS Windows and Apple Mac OS X)...

ANN: FireDataGrid 1.0 beta 3 for Delphi XE6 (Firemonkey) has been released! [Edit]
Dear colleagues, we are pleased to announce that version FireDataGrid 1.0 beta 3 for Delphi XE6 (Firemonkey) has been released. Version is quite stable and can be considered as a release candidate. This demo version adds two examples. MultiSelectDemo - demonstrates the ability to work in several selection modes (single row, multiple rows, single cell many cells, selection with rubber band and etc.). CustomEditorDemo - demonstrates the ability to embed custom cell editor to the grid view. In the example are being reviewed two options of the editors, based on embedded TControl and direct int...

Creating FireMonkey Objects at RunTime? [Edit]
I'm having difficulties creating FMX objects dynamically at runtime. The below code compiles, but no Circle makes itself known on Form1 - grateful for any pointers as to where I'm going wrong... (I didn't use a 'with' statement - as I'm not yet familiar with all the new FMX properties - so I'm glad of all the help code completion can offer!) {code}var MyCircle: FMX.Objects.TCircle; // I've tried this without 'FMX.Objects' as well begin MyCircle:=TCircle.Create(Form1); MyCircle.Width:=50; MyCircle.Height:=50; MyCircle.Position.X:=...

Error in help- creating a firemonkey component- [Edit]
1- function TDialogButtonPanel.GetStyleObject: TControl; is function TDialogButtonPanel.GetStyleObject:*TFmxObject*; 2- and in the same function Style = 'MyPanelButtonsStyle'; is Style = *'DialogButtonPanelStyle'*; The StyleName of the root (TRectangle) component in the .style file is coincidentally the same as the RCDATA name Please, review then for the future Edited by: Germán Balbi on Jul 14, 2013 12:31 PM > {quote:title=Germán Balbi wrote:}{quote} > Please, review then for the future If there's an issue with the help you&#...

How do you rate you experience programming for IOS in Delphi/Firemonkey [Edit]
Hello: I've been taking a IOS programming course in objective-c/swift with xcode, and while doing my homework assignments I came to the conclusion that this is a very finicky environment, where very often things don't work as expected or there is always some minor UI glitch that has to be fixed or found workarounds for. Just to give you some examples (by far not an exaustive list): a UITableView doesn't align to the top when you use a navigation controller; upon selecting a row in a UITableView some buttons in the row disappear while the row is selected; specifying layout con...

Does Delphi XE5 firemonkey work on current Samsung tablets? [Edit]
I am being told that Delphi XE5 with firemonkey will not work on the current range of Samsung tablets even if they have Android 4 is that true? If so I will be very disappointed having invested thousands of pounds and a few hundred hours to adopt the technology on the promise I can now deploy to Android mobile devices. When I run even the most simple Hello World app I simply get a black screen on my brand new Samsung tablet. I am told it only works on Android devices with a ARMv7 CPU supporting NEON instruction sets. If this is the case developers need to know that I have been told today ...

How to create runtime and design time packages using c++ and NOT Delphi [Edit]
Hello, I'm creating an Embarcadero component package, written in c++. Up to now, the runtime and design time parts were grouped together in my package, and I did not really need to have two versions of my package, because the difference in code between runtime and design time was very small. But now, I need to add a property editor in my package, meaning add a form that will be used exclusively on design time. I tried to separate my package in 2 distinct projects, one for runtime and other for design time, and f ollowing some documentation, I built the runtime part, then I added the de...

Delphi XE8 FireMonkey iOS Style problem with segmented buttons [Edit]
Hi, Going through some tutorials to get used to mobile development using FireMonkey and Delphi XE8. One of the most basic layouts tend to use the toolbar component with segmented speed buttons, and then applying the correct segmented style to each button. However, there seems to be an issue with the iOS style. [Screenshot.|https://drive.google.com/file/d/0B68Ju-patBf-RVVEMmI5UDd2cG8/view?usp=sharing] Using the "segmentedbuttonleft", "segmentedbuttonmiddle", and "segmentedbuttonright" styles is producing an extra border on the right button in iOS. It seems...

How to show custom cursor on transparent firemonkey form Delphi XE3 [Edit]
HI. In my application I need to show a semi-transparent form with specific cursor. A simple example: procedure TForm1.FormCreate(Sender: TObject); begin Fill.Kind := TBrushKind.bkSolid; Fill.Color := $50000000; Top := 0; Left := 0; Width := 600; Height := 600; Transparency := true; Cursor := crSQLWait; end; but cursor is changed only when I start mouse moving. I don't know how to fix it:( Edited by: Sam Rob on Apr 8, 2013 1:31 AM decision: I add to onActivate: Cursor := crSQLWait; Application.ProcessMessages; ...

Firemonkey app from Delphi XE2 -> Dropbox & iCloud [Edit]
Im developing an app for iOS and MacOS Is there any component or a way to connect to Dropbox and iCloud using Delphi XE2? > {quote:title=laureano bonilla wrote:}{quote} > Im developing an app for iOS and MacOS > > Is there any component or a way to connect to Dropbox and iCloud using Delphi XE2 For iCloud, you will need support for both iOS 5.0 and 10.7 Lion. I don't believe XE2 even supports the classes added with iOS 4.x, much less 5.0, although you can parse the iOS 5.0 UIKit and Foundation headers yourself: http://web.me.com/macpgmr/ObjP/Xcode4/iOS_5_Parsing_...

Touch Gestures in Firemonkey 3D application Delphi XE3 MacOS [Edit]
Hi! I'm trying to create a MacOS Firemonkey 3D application with gestures enabled but I can't make it work. I can place a GestureManager on the form but there is no Touch property on the TForm3D object. Then I've tried to create a TLayer3D with a normal TPanel where I was able to set the Touch property but the gestures didn't work although it captured any other mouse movements. Then I've created a separate HD TForm with a GestureManager and with the Touch property set which worked as a stand alone form but whe n I've linked a touch enabled TPanel on the HD TForm to t...

Delphi XE 5 / XE 6 Firemonkey custom component display problem
Hi everybody, I've a problem and I would like to know if you have encountered the same type of problem, and better, if you have solved it. Let's go for the explanation! With Firemonkey if you chose to create a new component derived from TListBox class with the wizard and you build and install it on a custom palet there is no problem. I mean that you can drag your own new component on a form and all is OK! But if you are doing the same thing with the TCustomListBox class as ancestor you can create your component without problem but when you drag this new one on a form you have ...

Web resources about - Delphi / FireMonkey release components created at runtime [Edit] - embarcadero.delphi.firemonkey

Firemonkeys - GamesIndustry International
The world's leading games industry website. Get insight from todays industry leaders with news, interviews and analysis of global gaming trends. ...

Firemonkey’s Real Racing 3 To Launch At The End Of February
In September, Apple demoed Firemonkey’s Real Racing 3 at the iPhone 5 event . Three months later and the game has yet to show up in the App Store. ...

EA Games and Firemonkey Bringing Real Racing 3 to Android, Fasten your Seat Belts
Start up your engines race fans, EA Games is teaming up with Firemonkey to bring Real Racing 3 to mobile devices. If you’re a fan of more realistic ...

EA's Firemint and IronMonkey Studios Merge to Become FireMonkeys
... game development studios into one mega-studio in Australia. Firemint and IronMonkeys will be merged into a single studio now known as Firemonkeys ...

News: Firemonkeys announces Real Racing 3
Firemonkeys, a new gaming subsidiary of Electronic Arts born from the merger of FireMint and IronMonkey, has announced the coming release of ...

firemonkeys - iMore
EA has pushed out another impressive update to its equally impressive iOS racer, Real Racing 3, that for the first time brings cars from Ferrari ...

Firemonkeys on Real Racing 3 going free-to-play
... got a hands-on preview of Real Racing 3. We also spoke with Ptolemy Oberin, one of the game’s programmers and project lead at developer Firemonkeys, ...

Real Racing 3 coming in 2012 from Firemonkeys
The first game from recently merged developer Firemonkeys is Real Racing 3 , the developer revealed moments ago during EA's Summer Showcase event ...

Firemonkeys Previews Real Racing 3 for iPhone and iPad
Firemonkeys, the new combined studio from EA combining the IronMonkey and Firemint gaming studios, has announced the development of Real Racing ...

EA Mobile Moves: IronMonkey & Firemint Merge Into “Firemonkeys,” Now Have 50M Players Between
... that it is merging two top mobile game studios, IronMonkey and Firemint , which will fittingly combine to create a new company, called Firemonkeys. ...

Resources last updated: 1/18/2016 11:06:46 AM