Page 1 of 3
Major bug in resource management
Posted: Tue Jul 27, 2010 3:46 pm
by Ricci
When working intensive with my HMG program after some time the controls began to disappear and the whole windows desktop was destroyed.
Using the Process Explorer I found out why this happens: while working the GDI handles grow and grow and when reaching 10000 the desktop becomes instable. 10000 hanles sounds really a lot and this is always enough, if a program close unused handles. HMG didn´t do this all the time.
Here´s a simple demonstration code:
Code: Select all
#include "minigui.ch"
Function Main
DEFINE WINDOW Form_1 ;
AT 0,0 ;
WIDTH 200 HEIGHT 100 ;
MAIN
@ 10,20 TEXTBOX TextBoxName ;
VALUE "" ;
WIDTH 100 HEIGHT 20 ;
FONT "ARIAL" SIZE 09
@ 40,60 BUTTON ButtonNew ;
PICTURE "document-edit.bmp" ;
ACTION ButtonClick() ;
WIDTH 30 HEIGHT 30 FLAT
END WINDOW
ACTIVATE WINDOW Form_1
Return Nil
// -------------------------------------------------------------------------------------------------------------------------------
Function ButtonClick()
local xx
for xx := 1 to 1000
Form_1.ButtonNew.enabled := .F.
Form_1.ButtonNew.enabled := .T.
next
Return Nil
As you can see, if you press the button the program only disables and than enables the grafik button 1000 times. Doing this the reserves 8000 GDI handles. If you press the button the 2nd time, some strange things will happen to your destop. Don´t fear, nothing will be destroyed.
Below you can download the samlpe and the grafik.
Re: Major bug in resource management
Posted: Tue Jul 27, 2010 4:04 pm
by Rathinagiri
Hmm. Sounds different and difficult.
I think Roberto can explain this.
Re: Major bug in resource management
Posted: Tue Jul 27, 2010 4:31 pm
by Ricci
I was trying it with another grafical element, the IMAGE control.
Here´s the code, this time i´m changing the picture of am IMAGE 1000 times:
Code: Select all
#include "minigui.ch"
Function Main
DEFINE WINDOW Form_1 ;
AT 0,0 ;
WIDTH 200 HEIGHT 100 ;
MAIN
@ 10,20 TEXTBOX TextBoxName ;
VALUE "" ;
WIDTH 100 HEIGHT 20 ;
FONT "ARIAL" SIZE 09
@ 40,60 BUTTON ButtonNew ;
PICTURE "document-edit.bmp" ;
ACTION ButtonClick() ;
WIDTH 30 HEIGHT 30 FLAT
@ 10,150 IMAGE lichtF PICTURE "lichtu.gif" WIDTH 35 HEIGHT 25
END WINDOW
ACTIVATE WINDOW Form_1
Return Nil
// -------------------------------------------------------------------------------------------------------------------------------
Function ButtonClick()
local xx
for xx := 1 to 1000
Form_1.lichtF.picture := "lichtb.gif"
Form_1.lichtF.picture := "lichtu.gif"
next
Return Nil
Here are the number of new GDI handles used for
a) grafical BUTTON control
<WindowName>.<ControlName>.Enabled := lEnabledState 4 handles
<WindowName>.<ControlName>.Visible := lEnabledState 0 handles
b) IMAGE control
<ParentWindowName>.<ControlName>.Picture := cImageName 1 handle
<WindowName>.<ControlName>.Enabled := lEnabledState 0 handles
<WindowName>.<ControlName>.Visible := lEnabledState 0 handles
For my program which uses a lot of grafical buttons and images with changes at every changed record this is a real disaster.
Re: Major bug in resource management
Posted: Wed Jul 28, 2010 6:46 am
by dhaine_adp
Hi Ricci,
It's great that you point out the GDI handle Leaks. While it is true that these leaks is a real problem against the application stability. However, you've never mentioned what O/S version, service pack and KB update installed on your test system. Of course we all do want to plug the GDI handle leaks.
I downloaded your posted test file for testing. It is really a major problem if just in case that all controls are leaking. Well it's too early to tell though.
Thanks for posting this info.
Regards,
Danny
Re: Major bug in resource management
Posted: Wed Jul 28, 2010 7:18 am
by dhaine_adp
Hi Ricci,
Using the Process Explorer I found out why this happens: while working the GDI handles grow and grow and when reaching 10000 the desktop becomes instable. 10000 hanles sounds really a lot and this is always enough. if a program close unused handles.
Yes, I agree with you, 10K is the default GDI Handle defined in the registry and we should think twice before increasing this value.
HMG didn´t do this all the time.
I don't know if all HMG Controls is leaking GDI Handles but through testing following your test code, one by one for each control, we'll be able to find if all of them is leaking. It could be from the core libs or from the windows GDI itself. At this point I am wondering if this problem do exist with HMG Extended because it use BCC as it's compiler...
Regards,
Danny
Re: Major bug in resource management
Posted: Wed Jul 28, 2010 8:20 am
by Ricci
dhaine_adp wrote:Hi Ricci,
However, you've never mentioned what O/S version, service pack and KB update installed on your test system.
It is really a major problem if just in case that all controls are leaking.
Hi Danny !
I use WinXP SP3 with all updates, but i´m sure this will happen on all other Win systems.
I think this only happens with controls that use grafik elements, i.e. IMAGE and BUTTON with PICTURE.
Regard ... Ricci
Re: Major bug in resource management
Posted: Thu Jul 29, 2010 8:10 am
by dhaine_adp
Hi Ricci,
I run your test app and have seen the effect of GDI handle leaks. Apparently the disappearance of the form controls is cause by lack of handles. IMHO Windbg can help to locate the problem. Unfortunately I can't download it from my connection at home. I'll try it from my office connection.
As of the moment I was planning to modify your test code and put it into a child window to get the full view of the handles once that window is terminated. It is more apparent that the image handle is not release that causes the leaks.
Ciao,
Danny
Re: Major bug in resource management
Posted: Thu Jul 29, 2010 9:54 am
by Ricci
Danny,
you can use the Sysinternals Process Explorer to see the increasing number of GDI handles.
Re: Major bug in resource management
Posted: Thu Jul 29, 2010 12:13 pm
by dhaine_adp
Hi,
you can use the Sysinternals Process Explorer to see the increasing number of GDI handles
Thanks for pointing out Sysinternals.
Well the main reason I'm interested with Windbg (
http://www.microsoft.com/whdc/ddk/debugging/ ) is that it can function as Kernel and User Mode/Interface App debugger. So that it can possibly tell which line of code or which portion of the source code the leaks came from against the library source code.
Anyway I hope that you posted the error in HMG Bugreport.
- Danny
Re: Major bug in resource management
Posted: Thu Jul 29, 2010 6:47 pm
by gfilatov
Ricci wrote:When working intensive with my HMG program after some time the controls began to disappear and the whole windows desktop was destroyed.
Using the Process Explorer I found out why this happens: while working the GDI handles grow and grow and when reaching 10000 the desktop becomes instable. 10000 hanles sounds really a lot and this is always enough, if a program close unused handles. HMG didn´t do this all the time.
...
As you can see, if you press the button the program only disables and than enables the grafik button 1000 times. Doing this the reserves 8000 GDI handles. If you press the button the 2nd time, some strange things will happen to your destop. Don´t fear, nothing will be destroyed.
Hello Ricci,
Thanks for your bugreport!
There is a simple solution for this problem. We should replace some strings
DeleteObject ( _HMG_SYSDATA [ 37 ] [y] ) with
IMAGELIST_DESTROY ( _HMG_SYSDATA [ 37 ] [y] ) in the
h_controlmisc.prg and recompile HMG library by batch file hmg\source\makehmg.bat.
You have an updated (and tested) patch in the attachment of this message.
Hope that helps
