title: When does std::shared_ptr release its object?
body: <p>I'm on Ubuntu 14.04 using GCC 4.8.4 and I have code similar to the following:</p>
  
  <pre><code>std::shared_ptr&lt;MyClass&gt; my_shared_object = set elsewhere...
  MyFunction(*my_shared_object);
  </code></pre>
  
  <p>Where <code>MyFunction</code>'s signature looks like this:</p>
  
  <pre><code>void MyFunction(const MyClass&amp; my_object)
  </code></pre>
  
  <p>The full code can be found <a href="https://github.com/sweeneychris/TheiaSfM/blob/master/src/theia/matching/feature_matcher.h#L403" rel="nofollow">here</a></p>
  
  <p>However, I am finding that my_object actually goes out of scope within the context of <code>MyFunction</code>. My thought was that the <code>my_shared_object</code> will only release its contents once it goes out of scope, meaning after the <code>MyFunction</code> has returned. I am not sure if I am either misunderstanding <code>std::shared_ptr</code> or if maybe this is a GCC bug.</p>
  
  <p>I guess the question boils down to: <strong>when I dereference a std::shared_ptr, does that guarantee that the <code>std::shared_ptr</code> will persist as long as the dereference is being used?</strong></p>