[futurebasic] Re: When to dispose of Hndl& and Ptr&?

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : December 1997 : Group Archive : Group : All Groups

From: David Blache <microcsm@...>
Date: Fri, 5 Dec 97 00:15:05 -0600
Bill Kuck wrote:

>I am confused about when I should (or should not) include statements to
>dispose of handles and/or pointers.  Consider the FN below that creates a
>resource file and does two things that got me to this state:
>First, I read in a technical note, that we should never need to use CALL

Correct.  It will be a very rare instance where you will need to use this 
call.  What you DO need to do though, is make sure that all of your 
resources are marked as purgeable in ResEdit or Resorcerer (with the 
single exception of MENU resources).  If a resource is purgeable, there 
is no need for you to release it or dispose of it.  The Memory Manager 
WILL DO IT FOR YOU - AUTOMATICALLY!  I have a hard time getting people to 
understand this.

>Secondly, do we really need to dispose of handle H& since
>it is in an FN and will be essentially done away with when we exit the FN?
>(I don't know why, but, I feel I just asked a stupid question).

That's incorrect.  You do need to dispose of it.  When you allocate a 
handle via NewHandle, it sits in your heap until you deallocate it or it 
is purged.  New handles by default are not purgeable.  So if you create a 
handle, and then leave the function, that handle will float around your 
heap until you quit your application.  I make it a rule to always write 
my DEF DISPOSEH (or Call DisposeHandle) immediately after I do a 
NewHandle.  That way I won't forget to write it later.  ;-)

|       David Blache - Developer       |
|   Staz Software, Inc - Stazologist   |
|        (tech@...)       |
|   Microcosm Software, Inc. - Owner   |
|        (microcsm@...)        |