[fpc-pascal] methods of an object to create others objects

Mattias Gaertner nc-gaertnma at netcologne.de
Mon Jul 5 22:50:38 CEST 2010


On Mon, 5 Jul 2010 17:46:39 -0300
Marcos Douglas <md at delfire.net> wrote:

> On Mon, Jul 5, 2010 at 5:30 PM, Mattias Gaertner
> <nc-gaertnma at netcologne.de> wrote:
> >
> > No. This will create a mem leak.
> 
> Thanks Mattias, I expect that...
> 
> 
> On Mon, Jul 5, 2010 at 5:39 PM, Martin <fpc at mfriebe.de> wrote:
> >
> > that is the same as if you wrote
> >
> >  TsomeObject.create;
> >
> > without assigning the created object to a variable. Both cause a memory
> > leek.
> >
> > Mind you just because "Create" is a constructor does not protect it from
> > being called without using the result.
> 
> Yes, as Mattias said too.
> 
> This type of construction should be banned, no?

No.

TForm1.Create(Application);

Application will free the TForm1.


> Different this, some times I use OUT parameters to force the caller to
> receive the result.


Mattias



More information about the fpc-pascal mailing list