You can get the behavior you expect by setting OBJC_DISABLE_TAGGED_POINTERS
to YES
in the program's environment. For example, you can set it in your scheme in Xcode like this:

What's going on (if you don't set that environment variable) is the Objective-C runtime supports tagged pointer strings. This means that short strings of common characters are encoded entirely in the 64-bit object reference, stored in the str
variable. There is no heap allocation. Since there is no heap allocation for the string, and since the string cannot itself have references to other objects, the runtime knows it doesn't actually need to arrange for the __weak
variable to be set to nil, so it doesn't.
By setting that environment variable, you disable the use of all tagged pointers, including tagged pointer strings. So I wouldn't recommend it for production code.
You can read more about tagged pointer strings in this excellent article by Mike Ash.