[plt-dev] GDI handle leak when misusing set-width on a pen%

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Wed Jul 29 09:55:57 EDT 2009

This is fixed in SVN. The `set-width' method now checks whether the
modification is supposed to be allowed and raises an exception if not.

Thanks for the report!

At Mon, 27 Jul 2009 23:46:06 +0200, Jakub Piotr Cłapa wrote:
> I had some problems with a long running MrEd app which I managed to 
> distill into this small script:
> 
> 
> #lang scheme/gui
> (define bm (make-object bitmap% 100 100))
> (define dc (make-object bitmap-dc% bm))
> 
> (for ([i (in-range 100)])
>    (send dc set-pen "white" 5 'solid)
>    (send (send dc get-pen) set-width 1)
>    (send dc set-pen "white" 1 'solid))
> 
> 
> After running the loop the GDI handle count in Process Explorer jumps by 
> 100 and it never gets back (even after a custodian shutdown by Ctrl-K). 
> OTOH in my actual app custodian shutdowns seemed to release these 
> handles (at least sometimes). After the counter reaches 10000 (on the XP 
> Prof. computer I tested on) strange things happen when the app (or the 
> system) tries to redraw anything on the screen.
> 
> After re-reading the documentation I understand that set-width can be 
> used neither on pens selected in a DC nor on ones that are obtained from 
> a pen-list (which IIUC is implied by using set-pen) so I screwed up 
> twice. ;]
> Maybe an exception would be helpful here?
> 
> -- 
> regards,
> Jakub Piotr Cłapa
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-dev


Posted on the dev mailing list.