Funny, I thought starting to use .NET would help with some of this stupid
Windows behavior. Not so. My first real .NET application sucked up GDI
Dispose()'ing them. Turns out they don't give back handles even when
garbage collected if you don't do that manually.
complete red herring path while debugging.
most annoying parts of coding multimedia software. I can't blame Peter for
being a little confused about it. The whole font creation and usage thing
in MFC is just too cumbersome. That is something that .NET got right. You
about destroying it or whether it's still available or ...
On Mar 16, 1:54 pm, "Peter Olcott" <NoS...@OCR4Screen.com> wrote:
It looks like all of this may be moot
because DeleteObject() is confirming that the object is
being deleted while it is selected by its return value of 1,
so my code is already good the way that it is. I only tested
this with VS 2008, but, it works on Windows 7 and XP.
Man, Joe is telling you repeatedly that you are mistaken. I told you
to try some GDI resource monitor program and see whether your GDI
objects indeed do get destroyed. I now believe that you didn't try
that and that you don't actually know more about that except
DeleteObject returned true. That is NOT ENOUGH.
But fine, don't trust us. Try this: start your task manager and add
"GDI objects" column. Make a test program where you create (or get) a
DC, then create a font, select it into a DC, and then call
DeleteObject on it. Watch GDI object count for your process. Did you
see that count dropped by 1 when you called DeleteObject? No you
haven't, despite the fact that DeleteObject returned TRUE.
BTW, if you do this, you WILL see that GDI object count drops, but
only when your DC (not font, DC) is destroyed. So that might mean that
some sort of reference counting is employed for fonts, or it might
mean absolutely NOTHING, because, AFAIK, none of that is actually
Now, do the same for e.g. a pen. There, you will see that GDI object
count indeed does drop. This is in line with doc for DeleteObject who
says "Do not delete a drawing object (pen or brush) while it is still
selected into a device context.". That, IMO, hints at the following:
if you delete e.g. a pen, and then do LineTo, what pen is a DC
supposed to use to draw? There is no pen anymore! Perhaps situation is
different for a font, but wouldn't you say now that it's a mess
playing with DeleteObject like that? Just unselect it before
destruction and that's all.
So what you choose to do, is to distrust the documentation and
disregard honest advice of people you often see here, and to rely on
undocumented behavior that you observe in your particular use case. Do
you actually think that is a good way to write code? If so, then
perhaps you don't deserve to be helped.