{"id":108939,"date":"2023-10-30T07:00:00","date_gmt":"2023-10-30T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=108939"},"modified":"2023-10-30T06:51:58","modified_gmt":"2023-10-30T13:51:58","slug":"20231030-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20231030-00\/?p=108939","title":{"rendered":"What are the dire consequences of not removing all the properties that were set via <CODE>SetProp<\/CODE>?"},"content":{"rendered":"<p>A customer noted that the documentation for the <code>Set\u00adProp<\/code> function says,<\/p>\n<blockquote class=\"q\"><p>Before a window is destroyed (that is, before it returns from processing the <code>WM_<wbr \/>NC\u00adDESTROY<\/code> message), an application must remove all entries it has added to the property list. The application must use the <code>Remove\u00adProp<\/code> function to remove the entries.<\/p><\/blockquote>\n<p>What are the dire consequences of failing to remove properties?<\/p>\n<p>If you forgot to remove the property, the system will call <code>Remove\u00adProp<\/code> on your behalf, but it will also generate a debug message to remind you of your oversight.<\/p>\n<p>Removing properties is good for hygiene. It prevents the system from worrying that maybe you forgot something.<\/p>\n<p>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&#8217;s an indication that you leaked something.<\/p>\n<p>The text about cleaning up properties has been around for a very long time. I can&#8217;t prove it, but it&#8217;s possible that early versions of Windows did not clean up orphaned properties automatically and relied on the program to perform the cleanup.<\/p>\n<p><b>Bonus chatter<\/b>: 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 <code>SetProp(windowHandle, \"property_name\", value)<\/code>, and it cleaned up the property by calling <code>Globall\u00adDeletel\u00adAtom<\/code> on the property ID. This meant that if you added the string property by atom:<\/p>\n<pre>ATOM property_atom = GlobalAddAtom(\"property_name\");\r\n\r\nSetProp(window1, MAKEINTATOM(property_atom), value);\r\nSetProp(window2, MAKEINTATOM(property_atom), value);\r\n<\/pre>\n<p>and you forgot to remove the properties from the two windows, the system would double-delete the atom. The first deletion would invalidate your <code>property_<wbr \/>atom<\/code>, and the second one might delete somebody else&#8217;s atom who got assigned the same numerical value as your now-deleted atom.<\/p>\n<p>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 <code>Global\u00adDelete\u00adAtom<\/code> only for those that were added by passing a string as the second parameter to <code>Set\u00adProp<\/code>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Not so much any more, but it could be a sign that you forgot something.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-108939","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Not so much any more, but it could be a sign that you forgot something.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/108939","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=108939"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/108939\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=108939"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=108939"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=108939"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}