Re: [Bug Suspicion] So, <any_gdi_object>.Dispose() does ... what exactly?
From: Philipp Schumann (phil_at_mokka.org)
Date: 02/23/05
- Next message: Philipp Schumann: "Re: Calling all MVPs and GDI+ gurus..."
- Previous message: Teis Draiby: "Re: How do I view and edit the alpha channel of a bitmap"
- In reply to: Robbe Morris [C# MVP]: "Re: [Bug Suspicion] So, <any_gdi_object>.Dispose() does ... what exactly?"
- Next in thread: Steve Austin: "Re: [Bug Suspicion] So, <any_gdi_object>.Dispose() does ... what exactly?"
- Reply: Steve Austin: "Re: [Bug Suspicion] So, <any_gdi_object>.Dispose() does ... what exactly?"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 23 Feb 2005 00:32:03 -0000
Hi Robbe,
Thanks for your message. I've compiled your app and have it running now. The
GDI objects counter in the task manager increases by 3 per every redraw -
the same as in my tool. (I've stated six before, but that was because my
task manager refreshed every two seconds or so, so it's actually three.)
I've had it running for some 10 minutes now and it already shows 1527 GDI
objects. I will keep it running to see whether the same sort of exception
occurs in your code after a couple of hours. At first glance, your code
seems to work similarly to mine, including the use of the Windows Forms
counter, the GetHicon call etc. The only difference being that I don't have
a Form, but I'd be surprised if this would be the cause of the exception at
my end. I will keep you and Bob updated on this. :)
"Robbe Morris [C# MVP]" <info@turnkeytools.com> schrieb im Newsbeitrag
news:uKWbOvTGFHA.1740@TK2MSFTNGP09.phx.gbl...
>I did not see this when I wrote an article for drawing icons from
> scratch for the system tray.
>
> http://www.eggheadcafe.com/articles/createiconsforsystemtray.asp
>
> --
> 2005 Microsoft MVP C#
> Robbe Morris
> http://www.robbemorris.com
> http://www.mastervb.net/home/ng/forumvbcode/post10017013.aspx
> http://www.eggheadcafe.com/articles/adonet_source_code_generator.asp
>
>
>
> "Philipp Schumann" <phil@mokka.org> wrote in message
> news:uIukmiPGFHA.1932@TK2MSFTNGP14.phx.gbl...
>> Hi,
>>
>> I have developed a very small Windows application which creates a new
>> Icon using .NET GDI+ every second (or every minute, that's
>> user-definable). I need to do this because my "drawing surface" is a
>> system tray icon so I can't just paint to a control or something.
>> However, whenever I replace the NotifyIcon.Icon property, whether it is
>> every second or every minute, I dispose of the previous icon. I also
>> dispose all GDI+ objects (Bitmap, Graphics, Brush, Pen) while drawing the
>> icon, using using{} clauses.
>>
>> I have double- and triple-checked that everything is disposed of in my
>> code. Now, while I keep the application running, when I open the task
>> manager (ctrl+alt+del) and make sure the "GDI objects" column is visible,
>> I have to realize that either every second or every minute, depending on
>> aforementioned user option, that number increases by 6. If the app has
>> run for a few hours, creating a new icon every second, the number
>> approaches several thousands, and eventually every time I call
>> Bitmap.GetHicon () to convert my image to an Icon raises the "A general
>> error occured in GDI+." exception. I suspect that is because an upper
>> limit of GDI handles had been allocated by the application - after all,
>> it doesn't seem to free the unused (disposed) handles of previous GDI
>> objects (remember that's six per second/minute, so it can't just be the
>> icon handle). However, the memory consumption of the app remains
>> constantly between 6 and 14 MB, typical for a small .NET app, so
>> Dispose() still seems to work correctly with regard to freeing up memory.
>>
>> Now, the application is not mission-critical, it's just a small, silly
>> clock for the system tray, so if this occurs, the simple workaround of
>> starting a new instance of the application and then immediately exiting
>> the current instance works fine and, from the "user's" point of view,
>> "resolves" the problem. Still it's a bit nasty and I was wondering
>> whether anyone has any idea on how to go about it. I have other, more
>> critical, long-running applications, for example ASP.NET applications,
>> that make heavy use of the GDI+ drawing and imaging APIs, and if this is
>> a general bug or so, then these applications could, after one or two
>> months of running, run into the same sort of problems, couldn't they?
>>
>> Many thanks,
>> Best regards,
>> Philipp Schumann
>>
>> P.S. the clock application and source code can be found at
>> www.mokka.org/clock if anyone wants to inspect the sources.
>>
>
>
- Next message: Philipp Schumann: "Re: Calling all MVPs and GDI+ gurus..."
- Previous message: Teis Draiby: "Re: How do I view and edit the alpha channel of a bitmap"
- In reply to: Robbe Morris [C# MVP]: "Re: [Bug Suspicion] So, <any_gdi_object>.Dispose() does ... what exactly?"
- Next in thread: Steve Austin: "Re: [Bug Suspicion] So, <any_gdi_object>.Dispose() does ... what exactly?"
- Reply: Steve Austin: "Re: [Bug Suspicion] So, <any_gdi_object>.Dispose() does ... what exactly?"
- Messages sorted by: [ date ] [ thread ]