title: Dangling reference. Alternatives for dangling pointers and references?
body: <p>The following code produces dangling references: </p>
  
  <pre><code>int main()
  {
    int *myArray = new int[2]{ 100, 200 };
    int &amp;ref = myArray[0];
    delete[] myArray;
    cout &lt;&lt; ref;  // Use of dangling reference.
  }
  </code></pre>
  
  <p>I know I shouldn't delete the array but in a large program what if somebody deletes memory to which I have a reference? Can it be somehow assured that no one deletes the array?</p>
  
  <p>What is the best strategy against dangling references and dangling pointers?</p>