Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!husc6!rutgers!cbmvax!vu-vlsi!swatsun!jackiw From: jackiw@cs.swarthmore.edu (Nick Jackiw) Newsgroups: comp.sys.mac.programmer Subject: Re: Ptrs, Handles, & Stuff Message-ID: <2466@ilium.cs.swarthmore.edu> Date: 21 Feb 89 16:58:51 GMT References: <7208@spool.cs.wisc.edu> Reply-To: jackiw@ilium.UUCP (Nick Jackiw) Distribution: usa Organization: Visual Geometry Project, Swarthmore College, PA Lines: 40 In article <7208@spool.cs.wisc.edu> drew@cat45.CS.WISC.EDU (Shawn Drew) writes: > Here's a simple question for you. What are the general rules of when to > dispose a ptr/handle and when not to (assuming I'm finished with it). > Sometimes I would dispose of a ptr/handle that I thought I was through with > and then crash. > > drew@cat45.cs.wisc.edu The general rule is simple: throw it away as soon as you're guaranteed never to need the data it holds again. The complications are anything BUT simple. Your crashes are the result of either someone (presumably NOT you) wanting data from the block you've already disposed, or YOU disposing of the block after someone else has already done that (double-disposes frequently crash). Faithful attention to InsideMac is the only way to know who wants what with your data and who's going to dispose it when. Some of the most common errors involve DisposeWindow and DisposeDialog, which dispose all sorts of other things (any controls in them, their resources, etc.); and the Resource Manager, which changes its idea of who owns what and whether it should clobber them just for fun as often as the wind... (:-) Good debugging...a discipline (i. e. with techniques) instead of a final bout of wishful hacking...is also necessary. If you're crashing and have reason to believe it's memory management related, first get a REPRODUCIBLE version of the crash. Then, reinvoking that crash consistently, use breakpoints to locate where it happens. Once you've found the offending line, if the bug isn't staring you in the face, you have to begin reverse-engineering the process that resulted in this line. If this means deleting all of your DisposeXXX() toolbox calls, and replacing them one by one til you find the one that's bad, so be it. "No silver bullet," the adage goes. -- +-------------------+-jackiw@cs.swarthmore.edu / !rutgers!bpa!swatsun!jackiw-+ | nicholas jackiw | jackiw%campus.swarthmore.edu@swarthmr.bitnet | +-------------------+-VGP/MathDept/Swarthmore College, Swarthmore, PA 19081--+ By the time my employer decides on its opinion, I'll be dead.