[comp.sys.mac.programmer] Correctly ending a program?

BRBOYER@MTUS5.CTS.MTU.EDU (Rucell) (04/29/91)

   When a program is "Quit" out of, what happens to all memory that the
program aloocated?  Should I close all my windows?  Should I dispose of all
pointers and handles, or does the memory manager close out everything for me?

   I have been experiencing intermittent bombing while in and out of my
program.  What is recommended?


   Bradley R. Boyer     ##### #   #  ###    BRBOYER@mtus5.cts.mtu.edu
                          #   #  #  #   #   BRBOYER%MTUS5.BITNET
 |"How could it have |   # #  ###   #####
 | been me?  I wasn't|    #   #  #  #   #   Phi Kappa Theta - Michigan Chi Rho
 | even there!"      |  ##### #   #  ###    Michigan Technological University

------ Posted using NetFeed, THE Macintosh <====> UseNet Interface Program ----

peirce@outpost.UUCP (Michael Peirce) (04/29/91)

In article <042891.202915BRBOYER@MTUS5.CTS.MTU.EDU>, BRBOYER@MTUS5.CTS.MTU.EDU (Rucell) writes:
> 
> 
>    When a program is "Quit" out of, what happens to all memory that the
> program aloocated?  Should I close all my windows?  Should I dispose of all
> pointers and handles, or does the memory manager close out everything for me?
> 
>    I have been experiencing intermittent bombing while in and out of my
> program.  What is recommended?

The memory goes back to the system and can be allocated to another
program later.

With things like handle data and such you needn't explicitly deallocate
these things if you are quiting.

On the other hand, there *are* some things that should be explicitly
deallocated.  Anything that is linked into system structures needs
to get unlinked.  For example, if you register an NBP name in AppleTalk,
that block of memory becomes the properly of AppleTalk and the name
must be unregistered before exiting.

-- michael

--  Michael Peirce         --   outpost!peirce@claris.com
--  Peirce Software        --   Suite 301, 719 Hibiscus Place
--  Macintosh Programming  --   San Jose, California 95117
--           & Consulting  --   (408) 244-6554, AppleLink: PEIRCE

neeri@iis.ethz.ch (Matthias Ulrich Neeracher) (04/29/91)

In article <042891.202915BRBOYER@MTUS5.CTS.MTU.EDU>, BRBOYER@MTUS5.CTS.MTU.EDU (Rucell) writes:
>   When a program is "Quit" out of, what happens to all memory that the
>program aloocated?  Should I close all my windows?  Should I dispose of all
>pointers and handles, or does the memory manager close out everything for me?

For applications, the memory manager handles this just fine, but usually,
I clean it up myself anyway. A good toilet training can be important for
other pieces of code for the Macintosh.

>   I have been experiencing intermittent bombing while in and out of my
>program.  What is recommended?

I doubt this comes from not doing any cleanup work. It seems more likely to
me that you didn't initialize some of the toolbox managers or made some
memory overrun error in your program.

Matthias

-- 
Matthias Neeracher                                      neeri@iis.ethz.ch
   "These days, though, you have to be pretty technical before you can 
    even aspire to crudeness." -- William Gibson, _Johnny Mnemonic_

hairston@henry.ece.cmu.edu (David Hairston) (04/30/91)

[BRBOYER@MTUS5.CTS.MTU.EDU (Rucell) writes:]
[]   When a program is "Quit" out of, what happens to all memory that the
[] program aloocated?  Should I close all my windows?  Should I dispose of all
[] pointers and handles, or does the memory manager close out everything for
[] me?
[]
[]    I have been experiencing intermittent bombing while in and out of my
[] program.  What is recommended?

the memory manager clears your application heap when you Quit.  however,
you don't want the memory manager governing your interface so at the
least undo the things you've done (i.e. close windows, etc. in a logical
manner).

the intermittent bombs (what error number?) are most likely caused by
incorrectly using handles and pointers.  if you have MacsBug (or some
debugger) installed then activate "Heap Scramble" (hs in MacSBug) or
its equivalent (something that forces memory to move on memory
management calls) so that you can uncover this type of bug.  heap
scramble slows down your application execution but that's a small price
to pay ...

  -dave-  
hairston@henry.ece.cmu.edu

2fmlcalls@kuhub.cc.ukans.edu (04/30/91)

In article <12838@pt.cs.cmu.edu>, hairston@henry.ece.cmu.edu (David Hairston) writes:
> [BRBOYER@MTUS5.CTS.MTU.EDU (Rucell) writes:]
> []   When a program is "Quit" out of, what happens to all memory that the
> [] program aloocated?  Should I close all my windows?  Should I dispose of all
> [] pointers and handles, or does the memory manager close out everything for
> [] me?
> []
> []    I have been experiencing intermittent bombing while in and out of my
> [] program.  What is recommended?

> the intermittent bombs (what error number?) are most likely caused by
> incorrectly using handles and pointers.  if you have MacsBug (or some
> debugger) installed then activate "Heap Scramble" (hs in MacSBug) or
> its equivalent (something that forces memory to move on memory
> management calls) so that you can uncover this type of bug.  heap
> scramble slows down your application execution but that's a small price
> to pay ...
> 
>   -dave-  
> hairston@henry.ece.cmu.edu

Although not too common for most programs, one pitfall I've encountered was
forgetting to dispose of sound channels my program had created.  This will
cause after-the-exit crashes.

john calhoun