Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
Member Area
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Become a Member
-Why sign up!
-Chat Online!
-Indexes NEW!!
-Build your resume
-Find a job
-Post a job
-Resume Search
-Link to us
Visit Embarcadero
Embarcadero Community
How to reduce the window and GDI handles an application is using Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Delphi 2.x
User Rating
No Votes
# Votes
DSP, Administrator
Reference URL:
			Author: Tomas Rutkauskas

I am trying to reduce the resources required to run my application. My application 
was pulling available resources down to 44%. I moved a large section of code 
containing two graphs out of an "available" form that does not get dynamically 
created and freed, into a separate form that is called with 
application.formcreate() and then freed after use.


Resources (the ones you can run out of in win9x) are things like window handles, 
menu handles, bitmap handles, handles of GDI objects like fonts, brushes, pens. 
These are not correlated with memory use or code size at all. All of these handles 
are used by Windows internally to reference some data structures for these objects 
(they are a kind of indirect pointer). The data structures are used by the 16 bit 
code that still makes up the core of Win9x/Me and come from a restricted pool of 
memory, a set of 64KByte memory blocks that are not extensible (the infamous USER 
and GDI heaps, USER and GDI are two of the core Windows modules).

The way to deal with resource-shortages is to reduce the number of window and GDI 
handles your app is using at any time. And the recipes for that are:

Do not autocreate your forms, with the exception of the main form. All other forms 
(at least the ones only used modally) should be created as needed and destroyed 
when no longer needed. Note that calling Close on a form will NOT destroy the forms 
memory image (and control handles), by default it only hides the form. For modeless 
forms you need a handler for the OnClose event of the form that sets the Action 
parameter to cafree. For modal forms you manually call the Free method of the form 
after the ShowModal call returned.
Try to replace controls that use Window handles with TGraphicControl descendents, 
e.g. TPanels and TGroupBoxes by TBevels. TGraphicControls do not use window 
handles, TWinControls do. Some, like TCombobox, even use more than one window 
If you use tabbed notebooks or pagecontrols a lot you can save resources by 
destroying the window handles of controls on hidden pages of the notebook, using 
the controls DestroyHandle method.
Replace groups of TEdit controls with a TStringGrid. A grid uses only two window handles, regardless how many cells it has.

Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10


Share this page
Download from Google

Copyright © Mendozi Enterprises LLC