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

Master resource purging


Basically, you should mark all resources you create _except MENU resources_ as purgeable. CODE resources should be left the way that FB sets them up. Don't change them.

You should not change the resource attributes of CODE resources. All other resources you create should be marked purgeable.

David Blache


You should also mark anything that the system is going to use as non-purgeable. I was just reading up on an interesting bug in WDEF, CDEF, etc. resources--apparently some commercial applications have these resources marked as purgeable and this causes crashes on quits or context changes. Using ResEdit to mark these resources as non-purgeable fixes the problem.

wave


This is good advice, but there are also a couple of other things to consider:

* If you are really, truly done with the resource, then you might as well call ReleaseResource. There's housecleaning done when a resource is released, that _isn't_ done when it's purged. Specifically, when a resource is purged the Memory Manager won't release the block's master pointer (because the thought is that you may wish to read a purged resource back into memory using the same handle). Purgeability wasn't designed as a means of automatic "garbage collection"--it was designed as a way to let things be (temporarily) swapped out of memory when memory is scarce.

* You need take additional care when working with a purgeable resource--namely, when you want to directly access or alter the data, you need to make sure the resource hasn't already been purged! Calling HNOPURGE won't do much good if the resource is already gone from memory. You should also always call LOADRESOURCE if you think there's any chance the resource might have been purged since the time you first got its handle.

Rick


That's a good point. Although I can't think of a case where the average FB programmer would have to worry about how many masters his program uses. Maybe in an application like a resource utility such as ResEdit or something like that it might be beneficial to clean up after yourself where masters are concerned. But I think for most people, making the resources purgeable is all that is needed. I could be wrong...

David Blache