<div dir="ltr">I realise there is a helpful section on this in<div><br></div><div><a href="https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Checking-memory-access">https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Checking-memory-access</a></div><div><br></div><div>which I'm now reading.</div><div><br></div><div>Thanks for your help.</div><div><br></div><div>Best,</div><div><br></div><div>Rajen</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 11 August 2016 at 10:45, Rajen Shah <span dir="ltr"><<a href="mailto:rds37@cam.ac.uk" target="_blank">rds37@cam.ac.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span class="">> <span style="font-size:12.8px">Have you tried running your code on the Mac after setting gctorture(TRUE)?</span><div><span style="font-size:12.8px"> </span></div></span><div><span style="font-size:12.8px">No I have not tried this (and no longer have the Mac available unfortunately). I have a very limited understanding of memory management, but I guess you're suggesting setting this to TRUE would make sure that freed memory really is free, and so would help uncover an issue where the code tries to use memory that it has declared free?</span></div><span class=""><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">> </span><span style="font-size:12.8px">By the way, valgrind showed the opposite of a memory leak - the code was using memory that it had declared free.  A leak is when the code does not free memory that it can no longer use.</span></div><div><span style="font-size:12.8px"><br></span></div></span><div><span style="font-size:12.8px">I am unfamiliar with how to interpret valgrid output, but are you deducing this from "allocs > frees"?</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Thanks: a useful way of finding the most horrible memory issue bugs it seems.</span></div><span class="HOEnZb"><font color="#888888"><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Rajen</span></div></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On 11 August 2016 at 10:33, William Dunlap <span dir="ltr"><<a href="mailto:wdunlap@tibco.com" target="_blank">wdunlap@tibco.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Have you tried running your code on the Mac after setting gctorture(TRUE)?<div><br></div><div>By the way, valgrind showed the opposite of a memory leak - the code was using memory that it had declared free.  A leak is when the code does not free memory that it can no longer use.</div></div><div class="gmail_extra"><span><br clear="all"><div><div data-smartmail="gmail_signature">Bill Dunlap<br>TIBCO Software<br>wdunlap <a href="http://tibco.com" target="_blank">tibco.com</a></div></div>
<br></span><div><div><div class="gmail_quote">On Thu, Aug 11, 2016 at 8:28 AM, Rajen Shah <span dir="ltr"><<a href="mailto:rds37@cam.ac.uk" target="_blank">rds37@cam.ac.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Many thanks Bill and Dirk.<div><br></div><div>I'm now explicitly casting each element and this works fine. I was just surprised that this inappropriate use of wrap would cause a memory leak on certain OS's and run without problems on others.</div><div><br></div><div>Best wishes,</div><div><br></div><div>Rajen</div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On 11 August 2016 at 10:18, 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>
To follow-up, if we avoid the cast this works just find as you'd expect:<br>
<br>
R> cppFunction("NumericVector myrunif() { return floor(runif(1000000)); }")<br>
R> for (i in 1:100) ignoreme <- myrunif()<br>
R><br>
<span><font color="#888888"><br>
Dirk<br>
</font></span><div><div><br>
--<br>
<a href="http://dirk.eddelbuettel.com" rel="noreferrer" target="_blank">http://dirk.eddelbuettel.com</a> | @eddelbuettel | <a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a><br>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>