Re: [Rd] optim/vmmin and R_alloc

From: Thomas Lumley <tlumley_at_u.washington.edu>
Date: Sat 01 Jan 2005 - 11:08:37 EST

On Fri, 31 Dec 2004, [iso-8859-1] Göran Broström wrote:

>

> Regarding 2., I tried the combination vmaxget + Calloc + vmaxset, ie, I
> began my function with vmax = vmaxget() and ended it with
> vmaxset(vmax). The point with this is that you can free all allocated
> memory with one call instead of repeated calls to Free. This seemed to work
> well; however, it is undocumented, and may well be completely wrong.

I think it's completely wrong. Free is just a wrapper for free() from the C library, and vmaxset() works only on the R heap and contains no calls to free(), so they shouldn't intersect at all. The memory leak will happen outside the R heap, and it may be less obvious there as long as you aren't short of virtual memory.

Calloc/Free still follow the basic C rule that you must call Free exactly once on each pointer returned by Calloc. The fact that Free sets its argument to NULL reduces somewhat the likelihood of damage from calling Free more than once, but only reduces it, since Free can't set other copies of the pointer to NULL.

         -thomas



R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat Jan 01 10:15:13 2005

This archive was generated by hypermail 2.1.8 : Sat 01 Jan 2005 - 11:17:28 EST