views:

60

answers:

2

Hi.

A single class derived from TForm appears to hold onto GDI handles until the application is closed.

class TTestForm : public TForm {
  public:
    TTestForm(TComponent*);
};

std::auto_ptr<TTestForm> test(new TTestForm(NULL));
test->ShowModal();

I'm quite new to VCL, so please bear with me. This test was done with a form that contains no controls. As far as I udnerstand, all objects are owned by the Application if no owner is specified.

My application creates (and destroys) a lot of forms dynamically. 3-4 new GDI handles are allocated each time a form is displayed. Is there a way to explicitly release those GDI handles during application lifetime?

A: 

Caveat: I'm a Delphi programmer, not C++, but the VCL is basically the VCL. You can try the form's Release() method instead of free(). Or alternatively, in the OnClose event set the Action parameter passed to caFree - thats supposed to tell the VCL to free the window's resources when the form closes, rather than hiding it.

I guess another question is - do you need to keep creating/destroying the forms? Can you create them once and then reuse them?

GrandmasterB
@GrandmasterB: I believe I've tried both options and they made no difference. I will double check again. Keeping the forms alive is simply not an option.
Chris Bednarski
You might check Emb's site to see if this is a know problem. Its possible there's a leak in 2007 that just cant be gotten around using vcl methods.Also, is it possible that there's something on the forms that are leaking? ie, its not the form itself, but one of the controls? Does the same problem occur if you specify an owner?
GrandmasterB
A: 

It turns out that the leak was caused by an incorrectly set TImageList.ShareImages property.

Chris Bednarski