title: mex file is crashing, how to use MATLAB_MEM_MGR in matlab?
body: <p>I have compiled a c++ code to MEX-file, but on calling this MEX-file, it crashes.
  It gives the following error message in MATLAB:</p>
  
  <blockquote>
    <p>Segmentation violation detected</p>
  </blockquote>
  
  <p>I tried using try-catch in C++ file to print the message in the catch block
  like,</p>
  
  <pre><code>try {
      //my code;
  }
  catch(std::exception &amp;e)
  {
      mexPrintf(e.what());
      mexEvalString("drawnow;");
      return;
  }
  </code></pre>
  
  <p>but the print message does not work and the code still crashes. </p>
  
  <p>On looking at Google, most of the time it points to some form of message given by MathWorks: <a href="http://www.mathworks.de/matlabcentral/newsreader/view_thread/25900" rel="nofollow">http://www.mathworks.de/matlabcentral/newsreader/view_thread/25900</a></p>
  
  <p>which instructs to set a environment variable <code>"MATLAB_MEM_MGR=debug"</code>,
  but it does not explain how to use it? Can anyone please explain it?</p>