[futurebasic] Re: [FB] RELEASERESOURCE

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : October 1999 : Group Archive : Group : All Groups

From: Joe Lewis Wilkins <PepeToo@...>
Date: Sun, 24 Oct 1999 21:11:13 -0700
AlStaff@... wrote:

> (using FB II)
> What happens if I CALL RELEASERESOURCE (handl&) on a handle that isn't a
> resource handle (created in the program).

It appears that nothing happens.

> My problem is I don't always know whether the handle is from the resource
> file or if it was created in the program. I was just calling RELEASERESOURCE
> and I thought that it also called DISPOSHANDLE, but it seems RELEASERESOURCE
> is doing nothing if the handle isn't a res handle, causing a memory leak in
> the program.

Is this because you're not creating the handle yourself? If that is the case, I
would think that "whatever" created the handle would be responsible for
disposing of it when no longer needed. Otherwise this "whatever" is pretty
negligent. Plus, if you're not allocating it yourself, how are you getting the
handle in the first place? There are a lot of handles around that you don't want
to "touch", even though you may use them "very gently" from time to time; like
some of the handles in Apple Records of one sort or another.

> I switched to
>   IF handl& THEN CALL RELEASERESOURCE (handl&)
>   DEF DISPOSEH (handl&)
> That seems to be working, but I was wondering if anyone thinks
> RELEASERESOURCE might still cause any problems if the handle isn't a resource
> handle.
>
> Your thoughts are appreciated.

Al, according to IM More MacIntosh Toolbox, page 1-107

"If the given resource isn't a handle to a resource, ReleaseResource does
nothing, and ResError returns the result code resNotFound." I quoted it
verbatim, but it seems as if it should have said: "If the given HANDLE isn't a
handle to a resource,...."

I believe that there are some other ramifications, however, that make it unwise
to call ReleaseResource "just in case"; even though it seems to work.

According to IM Memory page 2-34

"Do not use DisposeHandle to dispose of a handle obtained from the Resource
Manager (for example, by a previous call to GetResource); use ReleaseResource
instead. If, however, you have called DetachResource on a resource handle, you
should dispose of the storage by calling DisposeHandle.

I don't know why you have DisposeH and IM uses DisposeHandle, I suspect yours
may be an "obsolete" call. (Or maybe mine is!)

You may have already had this information at your fingertips. It is available
online I'm sure; although I use a Program called "ToolBox Assistant" which is
about 5 years old, but really handy.

Joe Wilkins