title: Eigen and Dynamic Allocation
body: <p>I have some mathematically computations in C++ that I'm moving to Eigen. Previously I've manually rolled my own <code>double*</code> arrays and also used <code>gsl_matrix</code> from the GNU Scientific Library.</p>
  
  <p>What confused me was the wording in the <a href="http://eigen.tuxfamily.org/index.php?title=Talk%3aFAQ#When_does_storage_get_freed_by_Eigen.3F" rel="nofollow">FAQ of Eigen</a>. What does that mean, is it that there's some kind of reference counting and automatic memory allocation going on?</p>
  
  <p>And I just need to confirm that this is still valid in Eigen:</p>
  
  <pre><code>// n and m are not known at compile-time
  MatrixXd myMatrix(n, m);
  MatrixXd *myMatrix2 = new MatrixXd(n, m);
  
  myMatrix.resize(0,0); // destroyed by destructor once out-of-scope
  myMatrix2-&gt;resize(0,0);
  delete myMatrix2;
  myMatrix2 = NULL; // deallocated properly
  </code></pre>