Which objects must be released explicitly
Which objects must be released explicitly
I know of FONT.
I am not sure about brush and pen.
Are there others?
Thanks in advance
Otto
I am not sure about brush and pen.
Are there others?
Thanks in advance
Otto
- Enrico Maria Giordano
- Posts: 7356
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: Which objects must be released explicitly
Generally speaking, any resources that you explicitly create you have to explicitly release.
EMG
EMG
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
- Enrico Maria Giordano
- Posts: 7356
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Enrico,
I was just saying that if you are not sure if you need to call End() then it is better to just do it and then you don't have to worry about resource leaks, files left open, etc.
James
Controls like gets and comboboxes, no, but I always end dialogs. How else do you close them?You don't need to explicitly End() TGets, TComboBoxes, TDialogs, etc.
I was just saying that if you are not sure if you need to call End() then it is better to just do it and then you don't have to worry about resource leaks, files left open, etc.
James
- Enrico Maria Giordano
- Posts: 7356
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Generally is the user that closes the dialog.James Bott wrote:Controls like gets and comboboxes, no, but I always end dialogs. How else do you close them?
I don't think this is a correct approach. It's always better to know what's going on. It's even possible (but I'm not sure) that double release can cause some kind of problems.James Bott wrote:I was just saying that if you are not sure if you need to call End() then it is better to just do it and then you don't have to worry about resource leaks, files left open, etc.
EMG
- Antonio Linares
- Site Admin
- Posts: 37485
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Enrico,
James
Ah, I guess you mean using the close button on the title bar. I remove those, so the user has to use the buttons on the dialog and the OK or Close button has to call oDlg:end().Generally is the user that closes the dialog.
I agree. I guess we would need a complete list of which classes need to be ended by the programmer and which don't.I don't think this is a correct approach. It's always better to know what's going on.
I have never run into such a problem, but I suppose it is possible.It's even possible (but I'm not sure) that double release can cause some kind of problems.
James
- Antonio Linares
- Site Admin
- Posts: 37485
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Please review Class TWindow Method Destroy() source code 
Any other GDI object that is not listed there as a DATA, has to be End()ed manually, as Enrico has pointed.
Anyhow, Windows automatically will take care of those GDI objects even if we don't explicity release them, when the app finsihes.
The problem only comes when a GDI object is created again and again from the application, so the the GDI memory is wasted and Windows won't act as it doesn't know if they are still needed or not.

Any other GDI object that is not listed there as a DATA, has to be End()ed manually, as Enrico has pointed.
Anyhow, Windows automatically will take care of those GDI objects even if we don't explicity release them, when the app finsihes.
The problem only comes when a GDI object is created again and again from the application, so the the GDI memory is wasted and Windows won't act as it doesn't know if they are still needed or not.
- Enrico Maria Giordano
- Posts: 7356
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Ops! Yes, you are right. I forgot oDlg:End() in Close button.James Bott wrote:Ah, I guess you mean using the close button on the title bar. I remove those, so the user has to use the buttons on the dialog and the OK or Close button has to call oDlg:end().
As I already said, any resource you explicitly create (and I add now, you don't attach to a dialog or to a window) you have to explicitly release.James Bott wrote:I guess we would need a complete list of which classes need to be ended by the programmer and which don't.
EMG
- Enrico Maria Giordano
- Posts: 7356
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
- Antonio Linares
- Site Admin
- Posts: 37485
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Enrico,
http://msdn.microsoft.com/en-us/library ... S.85).aspx
"Handles to GDI objects are private to a process."
So when the process is finished, all its environment is cleared, unless you have created global handles (i.e. using GlobalAlloc()).
http://msdn.microsoft.com/en-us/magazine/cc301756.aspx
"... the documentation states that Windows takes care of releasing the resource used by a process when it exits ..."
http://msdn.microsoft.com/en-us/library ... S.85).aspx
"Handles to GDI objects are private to a process."
So when the process is finished, all its environment is cleared, unless you have created global handles (i.e. using GlobalAlloc()).
http://msdn.microsoft.com/en-us/magazine/cc301756.aspx
"... the documentation states that Windows takes care of releasing the resource used by a process when it exits ..."
Last edited by Antonio Linares on Fri Aug 01, 2008 11:04 pm, edited 1 time in total.
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Even though they will be cleaned up when the app ends, unreleased GDI objects can become a problem if the app is run for a long time. So for such apps as order entry, reservations systems, etc. which may be run continously it is more important to release these manually.Anyhow, Windows automatically will take care of those GDI objects even if we don't explicity release them, when the app finsihes.
James
- Enrico Maria Giordano
- Posts: 7356
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Sorry, but the docs says:Antonio Linares wrote:Enrico,
http://msdn.microsoft.com/en-us/library ... S.85).aspx
"Handles to GDI objects are private to a process."
So when the process is finished, all its environment is cleared, unless you have created global handles (i.e. using GlobalAlloc()).
"can use" doesn't mean that the GDI objects are automatically released when the process exits.GDI objects support only one handle per object. Handles to GDI objects are private to a process. That is, only the process that created the GDI object can use the object handle.
Sorry again, the docs says:Antonio Linares wrote:http://msdn.microsoft.com/en-us/magazine/cc301756.aspx
"... the documentation states that Windows takes care of releasing the resource used by a process when it exits ..."
Note "this is not enough".Even if the documentation states that Windows takes care of releasing the resource used by a process when it exits, this is not enough for server applications that must be extremely reliable.
EMG
- Antonio Linares
- Site Admin
- Posts: 37485
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Enrico,
There are only two ways to manage the memory: locally and globally.
Global memory is shared by the entire operating system. Local memory is allocated from the heap of a process. The heap is local to a process and when the process is released, its heap is also cleared.
This is common to all operating systems.
Anyhow if you want to read the exact words from Microsoft, then lets keep googling for it
There are only two ways to manage the memory: locally and globally.
Global memory is shared by the entire operating system. Local memory is allocated from the heap of a process. The heap is local to a process and when the process is released, its heap is also cleared.
This is common to all operating systems.
Anyhow if you want to read the exact words from Microsoft, then lets keep googling for it
