Debugging incorrect usage of __weak variable in an Objective C++ class
<p>I have the following <code>-dealloc</code> implementation in my Objective-C++ class (MyObjectiveCppClass):</p>

<pre><code>- (void)dealloc {
  if (_my_iVar) {
    [_my_iVar doSomeSlowishCleanUp];
  }
}
</code></pre>

<p>Whenever this <code>-dealloc</code> method is called I get a bunch of warnings like:</p>

<pre><code>objc[1254]: __weak variable at 0x1662a38c8 holds 0x19c70f408 instead of 0x160abe000. This is probably incorrect use of objc_storeWeak() and objc_loadWeak(). Break on objc_weak_error to debug.
</code></pre>

<p>When I break on <code>objc_weak_error</code> the stack looks like this:</p>

<pre><code>#0  0x0000000182395330 in objc_weak_error ()
#1  0x00000001823959d0 in weak_clear_no_lock ()
#2  0x000000018239f1e8 in objc_object::clearDeallocating_slow() ()
#3  0x000000018238e074 in objc_destructInstance ()
#4  0x0000000182d25fac in -[NSObject(NSObject) __dealloc_zombie] ()
----&gt; #5    0x00000001000a6c30 in -[MyObjectiveCppClass .cxx_destruct]
#6  0x0000000182382b54 in object_cxxDestructFromClass(objc_object*, objc_class*) ()
#7  0x000000018238e040 in objc_destructInstance ()
#8  0x0000000182d25fac in -[NSObject(NSObject) __dealloc_zombie] ()
----&gt;    #9 0x00000001000a691c in -[MyObjectiveCppClass dealloc] 
#10 0x0000000100611bc4 in -[SomeViewB .cxx_destruct]
#11 0x0000000182382b54 in object_cxxDestructFromClass(objc_object*, objc_class*) ()
#12 0x000000018238e040 in objc_destructInstance ()
#13 0x0000000182d25fac in -[NSObject(NSObject) __dealloc_zombie] ()
#14 0x0000000188233a90 in -[UIResponder dealloc] ()
#15 0x0000000187e78b08 in -[UIView dealloc] ()
#16 0x0000000187f60700 in -[UIScrollView dealloc] ()
#17 0x0000000182c049b4 in -[__NSArrayM dealloc] ()
#18 0x00000001006495cc in -[SomeViewA .cxx_destruct]
</code></pre>

<p>Does anyone have any tips on figuring out how to fix these warnings?</p>