home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.ms-windows.programmer.misc
- Path: sparky!uunet!microsoft!hexnut!jonka
- From: jonka@microsoft.com (Jonathan Kagle)
- Subject: Re: PETZOLD's COLOR PROGRAM AFU??
- Message-ID: <1992Aug31.181958.20704@microsoft.com>
- Date: 31 Aug 92 18:19:58 GMT
- Organization: Microsoft Corporation
- References: <1992Aug28.004811.7803@cis.ohio-state.edu>
- Distribution: usa
- Lines: 29
-
- In article <1992Aug28.004811.7803@cis.ohio-state.edu> lavigne@spaghetti.cis.ohio-state.edu (david lavigne) writes:
- >Has anybody else had the following problem with the colors program is PETZOLDs
- >PROGRAMMING WINDOWS book.
- >
- >The program is not giving up some resource and will eventually cause windows to
- >UAE or whatever the new term is. This happens after moving the scrollbox
- >thumbs for quite a while. Even terminating the program does not free the
- >resources.
- >
-
- This is a known problem with COLORS and Windows 3.1. The code uses
- DeleteObject to delete the colored brush before deselecting it from the
- device context (with SetClassWord). As a result, the DeleteObject fails
- and the brush is never deleted. When you run the slider up and down, you
- fill memory with brushes created by CreateSolidBrush.
-
- For some reason, Windows 3.0 was more forgiving, though the API guide
- clearly states (under DeleteObject):
-
- "An application should not delete an object that is currently selected into
- a device context."
-
- This problem isn't instantly obvious when glacing at the code because of
- all of the cute tricks that Petzold uses (in this case to save the use of
- a temporary variable). In general, when using a modern optimizing compiler,
- these tricks rarely pay off in terms of code quality, and can really make
- your programs harder to read and debug.
-
- -Jonathan
-