home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!malgudi.oar.net!caen!destroyer!gumby!kzoo!k044477
- From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
- Subject: Re: m e m o r y m a n a g e m e n t
- Message-ID: <1992Aug12.201804.14518@hobbes.kzoo.edu>
- Organization: Kalamazoo College
- References: <1992Aug12.192637.13847@adobe.com>
- Date: Wed, 12 Aug 1992 20:18:04 GMT
- Lines: 48
-
- jryan@adobe.com (Jim Ryan) writes:
- >I'm a tad cloudy on when/where the "Dispos(e)" routines need to be used
- >to clean up memory.
-
- Most of the questions like "do I need to dispose of a FooStruct's
- SubFooStruct manually, or will DisposeFooStruct() do it for me?" are
- answered in IM if you read carefully.
-
- In general, if NewFooStruct() gives you the option of passing NULL and
- letting the toolbox allocate it...it's exactly the same as if you call
- NewPtr() to get the memory and pass that pointer in. Allocating
- nonrelocatable stuff is fine if either (1) it's done early in your app's
- lifetime, _or_ (2) it doesn't hang around for very long--modal dialogs,
- for example, don't last too long.
-
- >2. Say I have a C function that has some local variables like:
- >Handle theHandle;
- >I guess what I'm not entirely sure of is, when does one need to dispose
- >of such variables, and when will they die with the termination of the
- >function?
-
- The space occupied by the _variables_ is on the stack, and will be
- reclaimed when you exit the function. That's only four bytes per handle
- or pointer, however, and you're probably concerned about the space which
- the variables _refer_to_. That won't be recovered until you call
- DisposXxx()...and if a function stores the result of NewHandle() in a
- local var and exits without cleaning up, you have no way of knowing what
- to pass to DisposHandle().
-
- >3. Resources... when do you dispose of them, release them, etc.
- ^^^^^^^
-
- Never! Unless you like a corrupted resource map. Always call
- ReleaseResource() on resources and DisposHandle() on non-resources.
- Release a resource when you're done with it, make it purgeable if you're
- not completely done but you don't need it right away.
-
- >4. Any other memory issues I've missed and/or should be aware of?
-
- It's a craft, not a science...it's pretty easy actually, once you get
- into it. Bo3b Johnson's "Leaks" dcmd is _invaluable_ for finding memory
- that you're not disposing of. It will save you many, many, many hours,
- and I'm not kidding about this.
- --
- Jamie McCarthy Internet: k044477@kzoo.edu AppleLink: j.mccarthy
- "I honestly don't have the time to bicker with you and explain
- everything to you. Nor do I have the time to devote to a proper
- debate about the Holocaust." - Dan "Maynard" Gannon, 20 July 1992
-