![]() The Problem with & (Simple) Fix to Purgeable WDEFsBy Matthew Xavier Mora and Troy GaulApple Developer Technical Support (DTS) |
CONTENTSDefining the ProblemThe Problem Scenario Why This Hasn't Been a Problem Before The Simple Fix Additional Notes & Comments Summary |
This Technote describes a problem with purgeable WDEFs and explains how to fix it simply by marking WDEF resources as non-purgeable. This Note is directed at application developers who include WDEF resources in their applications as well as developers who create WDEF code resources. |
Defining the ProblemLike other definition functions, WDEFs contain executable code that needs to be locked down in memory whenever it is executed. If your application is using a custom WDEF marked as purgeable, the Memory Manager may purge the WDEF resource in order to allocate additional memory in your application heap. The Window Manager will reload the WDEF resource if necessary before calling it. If your application is the "current" application, i.e. the one that is executing but may not necessarily be frontmost, the Window Manager can reload the WDEF resource. Everything works fine. |
The Problem ScenarioThe following is a sequence of events that may cause the problem to occur: The Window Manager calls your WDEF when it needs to redraw your windows even if your application is not current. It does this by calling your WDEF directly whenever your windows get erased. If the WDEF has been purged, the Window Manager will try to reload the WDEF. Since your application is not the "current" application, your application's context has not been restored and your resource chain is not the current resource chain. As a consequence, the Window Manager attempts to load a WDEF from the wrong resource chain. Since it can't find the WDEF, it calls SysError(87). |
Why This Hasn't Been a Problem BeforeThere are three reasons why this hasn't been a problem in the past.
|
The Simple FixThe simple fix to the problem of your WDEFs not being able to be reloaded is to mark your WDEFs as non-purgeable. This prevents the Memory Manager from purging the WDEF, so it is always available even if your application is not frontmost. |
Additional Notes & CommentsThe following are some important items that you may need to consider when working through the problem of purgeable WDEFs:
|
The problem with purgeable WDEFs can be fixed by simply marking their resources as non-purgeable.
![]() ![]() |
I would like to thank Troy Gaul for his wisdom in this area and Vik Rubenfeld for tracking down the problem. Thanks also to Brian Bechtel, Nitin Ganatra, Pete Gontier, Tom Maremaa, Tim Swihart, and Tom Maughan.