The Property Cache
Caching property values reduces memory overhead when multiple components have the same value for a property. For example, all components using the same font will share a single set of font property values through the cache rather than duplicating them for each component. This adds up to substantial savings in memory if you have a thousand text components that all use the same font. The property cache provides the most benefit for nested properties such as CODFontProperties, CODLineProperties, and CODEditProperties.
The CODPropertyCache class implements the property cache. Every Objective Views application must declare a global CODPropertyCache object. The following code segment declares a global property cache.
CODPropertyCache thePropCache;
The name assigned to the global property cache is unimportant because the constructor of the CODPropertyCache class assigns the “this” pointer to a static member variable.
The CODComponent class gets and sets property values by performing lookups in the property cache. If a lookup in the property cache results in a match then an existing cached property is returned. If the property value is not found in the cache, the CODPropertyCache class adds it to the cache. The IsEqual() function defined by the CODProperty class is used by the property cache to determine if two property values match. For a nested property such as CODFontProperties, IsEqual() compares all of the sub-properties.
You can purge the cache to free memory. This operation checks all of the property objects to find objects that are only referenced by the cache. If the operation finds any objects that only reference the cache, it removes them.