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

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

From: Bill Kuck <bypass91@...>
Date: Thu, 4 Dec 1997 01:22:03 -0500
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:

      CALL RELEASERESOURCE(H&)
      DEF DISPOSEH(H&)

First, I read in a technical note, that we should never need to use CALL
RELEASERESOURCE.  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).

I have seen several routines that use statements like these and then other
times they don't given similar conditions.  Anyone have all this worked out
and could summarize it for me?  BTW, this routine works fine if I give it a
filename that  doesn't exist in the folder, otherwise it crashes on
duplicating filenames - just after the "do you want to replace existing
file?".

CLEAR LOCAL
DIM 80 mystring$(2)
DIM volRefNum%,resRef%,osErr%,x%
DIM H&
LOCAL FN createRes
  mystring$(1) = "First string in this STR# resource."
  mystring$(2) = "Second string in this STR# resource."
  filename$ = FILES$(_fSave,"Create fileĀŠ",,volRefNum%)
  LONG IF filename$ <> ""
    volRefNum% = FOLDER("",volRefNum%)
    CALL CREATERESFILE(filename$)
    resRef% = FN OPENRESFILE(filename$)
    LONG IF resRef%
      H& = FN NEWHANDLE _clear(2)
      LONG IF H&
        osErr% = FN HLOCK(H&)
        POKE WORD [H&],0
        FOR X% = 1 TO 2
          DEF APNDSTR(mystring$(X%),H&)
        NEXT X%
        CALL ADDRESOURCE(H&,_"STR#",128,"")
        CALL UPDATERESFILE(resRef%)
        osErr% = FN HUNLOCK(H&)
        CALL RELEASERESOURCE(H&)       '<----
        DEF DISPOSEH(H&)               '<----
      END IF
      CALL CLOSERESFILE(resRef%)
    END IF
  END IF
END FN

PS:  Rick, hit me with it!