jls@hsv3.UUCP (James Seidman) (09/24/90)
Where in memory are objects stored? I'd most like to know if they're handled in such a way that they are automatically disposed when an application terminates, or if they always need to be explicitly removed with DeleteObject(). On a similar note, do you have to use DeleteObject() to remove an object obtained with GetStockObject()? (In fact, is it even considered valid to do so?) -- Jim Seidman (Drax), the accidental engineer. "There's a certain freedom to being completely screwed." - The Freshman UUCP: ames!vsi1!headland!jls ARPA: jls%headland.UUCP@ames.nasa.arc.gov
bcw@rti.rti.org (Bruce Wright) (09/26/90)
In article <4942@hsv3.UUCP>, jls@hsv3.UUCP (James Seidman) writes: > > Where in memory are objects stored? I'd most like to know if they're > handled in such a way that they are automatically disposed when an application > terminates, or if they always need to be explicitly removed with > DeleteObject(). I haven't tried this on Windows 3, but under Windows 2 objects are definitely NOT disposed of when the application terminates. I was writing an application once that created LOTS of pens and brushes, but there was a minor bug in the algorithm that ran around and deleted the old ones after it was through with them. After a while things got VERY strange ... all sorts of odd things would start to happen (not just in that program, and even after the program had exited). I'd be sort of surprised if Windows 3 added this sort of resource management - it's going to take significant space on the smaller machines, and Win3 just doesn't take up all that much more space in memory (some of the mini-apps distributed with it are a different story, but they're not the basic system itself). But I haven't really been interested in putting this to the test. > On a similar note, do you have to use DeleteObject() to remove an object > obtained with GetStockObject()? (In fact, is it even considered valid > to do so?) It is not valid to do a DeleteObject on objects you obtain with GetStockObject. Also, be sure that any objects you delete aren't selected into the current Device Context (or they won't be deleted). Windows doesn't do much resource management for programs - you need to explicitly delete anything you create (device contexts, pens, brushes, timers, etc), though of course they are created and deleted in different ways. But not keeping track of them properly is one of the easiest ways to wedge the system - Bruce C. Wright
kensy@microsoft.UUCP (Ken SYKES) (09/27/90)
In article <4942@hsv3.UUCP> jls@headland.UUCP (James Seidman) writes: > >Where in memory are objects stored? I'd most like to know if they're >handled in such a way that they are automatically disposed when an application >terminates, or if they always need to be explicitly removed with >DeleteObject(). Objects are not automatically disposed of. You must explicitly delete them. Not only that, the objects *usually* reside in the local heaps of USER or GDI, depending on the object. If you don't free them up then you are restricting the memory available to other apps. When checking for memory leaks keep an eye on USER and GDI's local heap and make sure you aren't leaving anything around. > >On a similar note, do you have to use DeleteObject() to remove an object >obtained with GetStockObject()? (In fact, is it even considered valid >to do so?) >-- Apps shouldn't delete StockObjects. Ken Sykes Disclaimer: The above opinions are solely my own.