Re: GDI Object Select leak question

"mmartinsson123" <[email protected]>
Newsgroups gmane.comp.windows.wtl
Message-ID <[email protected]>
--- In [email protected], "todd" <timza1221@...> wrote:
>
> if you select an object into a DC, then delete the object before selecting the previous object back into it, is it a memory leak?
> 
> hBrushOld = (HBRUSH) SelectObject(hdc, hBrush);
> 
> // you forget to do this: SelectObject(hdc, hBrushOld);
> 
> DeleteObject(hBrush);
> 
> since hBrush is still selected, is it not deleted?
>

Try that pattern:

{
  Get_GDI_Object;
  <some code>
  DeleteObject;
} -> forget about it!

Better is using the RAII-Idiom with the WTL GDI-wrapper classes ie. CBrushT<true> and you will never get an GDI leak, which is part of the C++ standard.

All GDI handles are internally cached, reference counted and recycled, when requested, so with hepa memory too. 

Globally you will never get any GDI or Heap leaks, because every process has it's own GDI-handle table and process heap.
When the process is destroyed all dynamic memory is released.

So, your question is only pratically of importance, when much memory is allocated, which must be promptly deallocated or concerning software quality and testing.

Cheers
Martin




------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/wtl/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/wtl/join
    (Yahoo! ID required)

<*> To change settings via email:
    [email protected] 
    [email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.