Forum Navigation
You need to log in to create posts and topics.

Re: When to call RELEASERESOURCE

Posted by: rbrown <rbrown@...>

M. Goodes wrote:
> 1. What happens if you call RELEASERESOURCE on a handle that's designated
> as non-purgeable? Will it still release the handle from memory?

Yes.

> 2. What happens if you call RELEASERESOURCE on a handle that's already
> been purged? Will your system crash or will you just get an osErr?

Neither. It kind of works like this:

When the Memory Manager _purges_ a resource, the block of memory that
contained the resource's data gets released, but the _handle_ itself (a
long integer value) remains "connected" to the resource. Specifically,
if resH& contains a handle to a resource that's been purged, you can
CALL LOADRESOURCE(resH&), and the resource's data will get reloaded back
into memory, and you can continue to use the same handle (the same value
of resH&) to refer to it. And that means that if you've made any copies
of the handle (i.e., if you've assigned resH&'s value to other long int
variables), then all of those copies are also still valid references to
the resource. This is good, because it means, for example, that you can
pass a resource handle to another function without worrying about
whether the resource has been purged or not. As long as the other
function is smart enough to call LOADRESOURCE with the handle that you
passed it, then it can always access the resource's data.

But if you call RELEASERESOURCE, then not only does the block of
resource data go away, but the handle itself gets wiped from the
Resource Manager's list of current handles. In that case, resH& still
contains the same long int value as before, but that long int value is
now meaningless to the Memory Manager & Resource Manager. If you call
LOADRESOURCE(resH&) using a handle that you've _released_, then you'll
get an error. In that case, the only way to get the resource's data
again is to call something like GETRESOURCE.

If you call RELEASERESOURCE(resH&) on a resource that's been purged,
then essentially the only thing that happens is that the value currently
in resH& can thereafter no longer be used to refer to the resource. No
error occurs.

- Rick