[Rd] Basic Question regarding PROTECT

Saptarshi Guha saptarshi.guha at gmail.com
Mon Aug 24 05:52:28 CEST 2009


Hello,
Suppose I have the function
SEXP foo(){
SEXP s;
PROTECT(s=allocVector(...))

....
UNPROTECT(1);
return(s)
}

y=foo() // foo is a recusrive call

Q: Am i correct in understanding that one does not need to write
PROTECT(y=foo()) ?(and a corresponding unprotect  later on)
since it is the object that is protected , SEXP is an alias for
SEXPREC* and allocVector probably does some memory allocation which
does not get freed
when foo returns.

Thank you for your time
Regards
Saptarshi



More information about the R-devel mailing list