FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

RESOURCES

Understand respurgeable vs RELEASERESOURCE


I was wondering if CALL RELEASERESOURCE will work in place of setting a resource's "purgeable" attribute, and vice versa. My guess is that using RELEASERESOURCE will free up the memory instantly, but if it is purgeable it waits for the memory manager to free it up when it needs the memory?

That's correct, but that's not the only difference between the two. When a resource gets purged, the Resource Manager still remembers its handle (even though the handle no longer references a block of memory). That means that if you have any copies of that handle lying around after the resource gets purged, those copies are still "valid" for certain purposes. You can pass that old handle value to various Toolbox routines that expect a resource handle, and they'll still work just as if the resource were still in memory (they'll reload the resource if necessary). If you pass the old handle to LOADRESOURCE, the resource gets reloaded from disk (and its old handle gets "reattached" to the newly-loaded block). If you call GETRESOURCE, it reloads the resource and returns the original handle value.

On the other hand, when you call RELEASERESOURCE, the Resource Manager not only releases the block but also makes the handle invalid. If you have any copies of the handle lying around after the resource is released, they are invalid, and you'll get an error if you try to pass them to any Toolbox routines. If you call GETRESOURCE, it reloads the resource and returns a _new_, different handle value.

Rick