<div dir="ltr">Hi, Wush,<div><br></div><div>It seems that memory leakage has nothing to do with R.</div><div><br></div><div>Just use your code without R:</div><div><br></div><div><div>#include <iostream></div><div>#include <stdexcept></div><div><br></div><div>int main(int argc, char **argv) {</div><div><br></div><div>    std::string msg = std::string("test");</div><div>    throw std::logic_error(msg);</div><div>    return 0;</div><div>}</div></div><div><br></div><div>I still get the same leakage information:</div><div><br></div><div><div>==19532== Memcheck, a memory error detector</div><div>==19532== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.</div><div>==19532== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for copyright info</div><div>==19532== Command: ./a.out</div><div>==19532== </div><div>terminate called after throwing an instance of 'std::logic_error'</div><div>  what():  test</div><div>==19532== </div><div>==19532== HEAP SUMMARY:</div><div>==19532==     in use at exit: 173 bytes in 2 blocks</div><div>==19532==   total heap usage: 3 allocs, 1 frees, 205 bytes allocated</div><div>==19532== </div><div>==19532== LEAK SUMMARY:</div><div>==19532==    definitely lost: 0 bytes in 0 blocks</div><div>==19532==    indirectly lost: 0 bytes in 0 blocks</div><div>==19532==      possibly lost: 173 bytes in 2 blocks</div><div>==19532==    still reachable: 0 bytes in 0 blocks</div><div>==19532==         suppressed: 0 bytes in 0 blocks</div><div>==19532== Rerun with --leak-check=full to see details of leaked memory</div><div>==19532== </div><div>==19532== For counts of detected and suppressed errors, rerun with: -v</div><div>==19532== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)</div><div><b>Aborted (core dumped)</b></div></div><div><br></div><div>The program may abort before releasing the resource, so there may be memory leak.</div><div><br></div><div>With try/catch, the program will exit normally. So no leakage found.</div><div><br></div><div>Best,</div><div><br></div><div>KK</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Dec 29, 2014 at 10:05 PM, Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
PS  Here is a better variant that actually leaks:<br>
<span class=""><br>
edd@max:/tmp$ cat leak.cpp<br>
<br>
#include <cstdio><br>
#include <cstdlib><br>
#include <iostream><br>
</span>#include <cmath><br>
<span class=""><br>
int main() {<br>
  double *d = new double[1024];<br>
  if (d) std::cout << "Allocated" << std::endl;<br>
</span>  double e = std::exp(1.0);<br>
  d = &e;<br>
  exit(0);<br>
<span class="">}<br>
edd@max:/tmp$ g++ -Wall -o leak leak.cpp<br>
edd@max:/tmp$ valgrind  ./leak<br>
</span>==16924== Memcheck, a memory error detector<br>
==16924== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.<br>
==16924== Using Valgrind-3.10.0 and LibVEX; rerun with -h for copyright info<br>
==16924== Command: ./leak<br>
==16924==<br>
Allocated<br>
==16924==<br>
==16924== HEAP SUMMARY:<br>
==16924==     in use at exit: 8,192 bytes in 1 blocks<br>
==16924==   total heap usage: 1 allocs, 0 frees, 8,192 bytes allocated<br>
==16924==<br>
==16924== LEAK SUMMARY:<br>
==16924==    definitely lost: 8,192 bytes in 1 blocks<br>
==16924==    indirectly lost: 0 bytes in 0 blocks<br>
==16924==      possibly lost: 0 bytes in 0 blocks<br>
==16924==    still reachable: 0 bytes in 0 blocks<br>
==16924==         suppressed: 0 bytes in 0 blocks<br>
==16924== Rerun with --leak-check=full to see details of leaked memory<br>
==16924==<br>
==16924== For counts of detected and suppressed errors, rerun with: -v<br>
==16924== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)<br>
edd@max:/tmp$<br>
<br>
By overwriting d the memory is lost for good, and valgrind notices as you;d<br>
think it would.<br>
<span class="im HOEnZb"><br>
Dirk<br>
<br>
--<br>
<a href="http://dirk.eddelbuettel.com" target="_blank">http://dirk.eddelbuettel.com</a> | @eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a><br>
</span><div class="HOEnZb"><div class="h5">_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">Qiang Kou<div><a href="mailto:qkou@umail.iu.edu" target="_blank">qkou@umail.iu.edu</a><br><div>School of Informatics and Computing, Indiana University</div><div><br></div></div></div></div>
</div>