3.4.0<br>I haven't built it yet, but did take a look at itkLightObject. Now&nbsp; UnRegister does correct multi-threading thing of _not_&nbsp; referencing a volatile value outside a semaphore, SetRegister() should do the same thing. It's just not thread safe to check values modifiable by another context. A race condition persists if one thread sets a reference count to zero and another decrements it to zero, both may attempt to delete the same piece of memory. A true pain to debug.<br><br>void<br>LightObject<br>::UnRegister() const<br>{<br>&nbsp; m_ReferenceCountLock.Lock();<br>&nbsp; int tmpReferenceCount = --m_ReferenceCount;<br>&nbsp; m_ReferenceCountLock.Unlock();<br><br>&nbsp; // ReferenceCount in now unlocked.&nbsp; We may have a race condition<br>&nbsp; // to delete the object.<br>&nbsp; if ( tmpReferenceCount &lt;= 0)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; delete this;<br>&nbsp;&nbsp;&nbsp; }<br>}<br><br><br>void<br>LightObject<br>::SetReferenceCount(int
 ref)<br>{<br>&nbsp; m_ReferenceCountLock.Lock();<br>&nbsp; m_ReferenceCount = ref;<br>&nbsp; m_ReferenceCountLock.Unlock();<br><br>&nbsp; if ( m_ReferenceCount &lt;= 0)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; delete this;<br>&nbsp;&nbsp;&nbsp; }<br>}<br><br><br>