Board index » delphi » Freeing Memory and GDI Resources

Freeing Memory and GDI Resources

I'm writing an application using bitmaps, Jpeg images, tPictures etc.  I'm
not really using all that many at any given time but I'm finding that I
easily exhaust resources...GDI resources especially.

How does one release memory from, for example, a TPicture when the TPicture
no longer needs to be displayed?

I know this is a basic question but I can't find the answer (at least it's
not clear to me) within Delphi help.

Can you point me to any good tutorials regarding working with graphics,
resources, what all consumes GDI resources (for example Spin controls?) and
resource allocation?

Thanks

Lee Marvin

 

Re:Freeing Memory and GDI Resources


Quote
Lee Marvin <lmarv...@worldnet.att.net> wrote in message 3b97aaa0_2@dnews...
> I'm writing an application using bitmaps, Jpeg images, tPictures etc.  I'm
> not really using all that many at any given time but I'm finding that I
> easily exhaust resources...GDI resources especially.

> How does one release memory from, for example, a TPicture when the
TPicture
> no longer needs to be displayed?

> I know this is a basic question but I can't find the answer (at least it's
> not clear to me) within Delphi help.

> Can you point me to any good tutorials regarding working with graphics,
> resources, what all consumes GDI resources (for example Spin controls?)
and
> resource allocation?

> Thanks

> Lee Marvin

There are some simple rules to follow to avoid resource leaks , the most
important is that if you create any object that allocates gdi resources you
always need to free it .
The create and free methods should be called in the same scope of course ,
so if you declare for example a Tbitmap within a procedure you have to
create and free it in that procedure (to create or free a Tbitmap you can
use the following : bitmap:=tbitmap.create; bitmap.free ).

Besides this , there are some components that allocate gdi resources when
they are created for example at the start of your application : for example
if you put a timage on a form it will contain some picture in it , so it
will take some resources . But these resources are taken and released
automatically when the timage component is created and when it is freed .

You should avoid having many timage or other "heavy" graphics components
created at the same time : to avoid this you can create dynamically your
forms (and so automatically the components they contain) : In your project
options you can leave as autocreated form only the main form , while you
create (and then release) the other ones by code by yourself .

If you need further help i can send you some example to show better these
simple concepts to you .

Francesco

Other Threads