What are the dire consequences of not removing all the properties that were set via
A customer noted that the documentation for the
SetProp function says,
Before a window is destroyed (that is, before it returns from processing the
WM_message), an application must remove all entries it has added to the property list. The application must use the
RemovePropfunction to remove the entries.
What are the dire consequences of failing to remove properties?
If you forgot to remove the property, the system will call
RemoveProp on your behalf, but it will also generate a debug message to remind you of your oversight.
Removing properties is good for hygiene. It prevents the system from worrying that maybe you forgot something.
Often, the value associated with the property is something that itself needs to be cleaned up, so if you fail to clean it up yourself, that’s an indication that you leaked something.
The text about cleaning up properties has been around for a very long time. I can’t prove it, but it’s possible that early versions of Windows did not clean up orphaned properties automatically and relied on the program to perform the cleanup.
Bonus chatter: The way the system automatically cleans up your forgotten properties may not be the way you wanted! Earlier versions of Windows would assume that any string properties were added by
SetProp(windowHandle, "property_name", value), and it cleaned up the property by calling
GloballDeletelAtom on the property ID. This meant that if you added the string property by atom:
ATOM property_atom = GlobalAddAtom("property_name"); SetProp(window1, MAKEINTATOM(property_atom), value); SetProp(window2, MAKEINTATOM(property_atom), value);
and you forgot to remove the properties from the two windows, the system would double-delete the atom. The first deletion would invalidate your
property_, and the second one might delete somebody else’s atom who got assigned the same numerical value as your now-deleted atom.
There were so many bugs traced back to people forgetting to clean up their integer atoms that Windows eventually added code to record how the property was added and to call
GlobalDeleteAtom only for those that were added by passing a string as the second parameter to