Something I&#x27;ve wondered about reference counting and optimising compilers: I assume at a lowish level an inlined function call might look something like,<p><pre><code>    pointer-&gt;ref_count += 1
    obj = pointer-&gt;ptr
    &#x2F;&#x2F;...do something with obj...
    pointer-&gt;ref_count -= 1
    if pointer-&gt;ref_count == 0:
        free(pointer-&gt;ptr)
</code></pre>
Assuming ref_count isn&#x27;t messed up by another thread (which I guess we&#x27;re free to do if we haven&#x27;t put locks around it, or declared it volatile?) then you could optimise away the increment and decrement on `ref_count`, right? I guess I wouldn&#x27;t be surprised either way.<p>What I&#x27;d like to know, though, is whether the `ref_count == 0` check could get optimised away as well. To you and me it&#x27;s obvious that the count is positive at the start (as a precondition for the pointer access being correct), but I can&#x27;t really see how an optimising compiler could know that.