Major bug in resource management

Moderator: Rathinagiri

Ricci
Posts: 255
Joined: Thu Nov 19, 2009 2:23 pm

Major bug in resource management

Post 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.
Attachments
test.zip
(1.05 KiB) Downloaded 309 times
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Major bug in resource management

Post by Rathinagiri »

Hmm. Sounds different and difficult.

I think Roberto can explain this.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
Ricci
Posts: 255
Joined: Thu Nov 19, 2009 2:23 pm

Re: Major bug in resource management

Post 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.
User avatar
dhaine_adp
Posts: 457
Joined: Wed Aug 06, 2008 12:22 pm
Location: Manila, Philippines

Re: Major bug in resource management

Post 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
Regards,

Danny
Manila, Philippines
User avatar
dhaine_adp
Posts: 457
Joined: Wed Aug 06, 2008 12:22 pm
Location: Manila, Philippines

Re: Major bug in resource management

Post 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
Regards,

Danny
Manila, Philippines
Ricci
Posts: 255
Joined: Thu Nov 19, 2009 2:23 pm

Re: Major bug in resource management

Post 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
User avatar
dhaine_adp
Posts: 457
Joined: Wed Aug 06, 2008 12:22 pm
Location: Manila, Philippines

Re: Major bug in resource management

Post 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
Regards,

Danny
Manila, Philippines
Ricci
Posts: 255
Joined: Thu Nov 19, 2009 2:23 pm

Re: Major bug in resource management

Post by Ricci »

Danny,

you can use the Sysinternals Process Explorer to see the increasing number of GDI handles.
User avatar
dhaine_adp
Posts: 457
Joined: Wed Aug 06, 2008 12:22 pm
Location: Manila, Philippines

Re: Major bug in resource management

Post 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
Regards,

Danny
Manila, Philippines
User avatar
gfilatov
Posts: 1067
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: Major bug in resource management

Post 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 :idea:
Attachments
h_controlmisc-upd.zip
Patch for GDI leaks problem
(33.25 KiB) Downloaded 304 times
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
Post Reply