[racket] scheme_make_vector gc macros

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sat Jan 1 10:06:38 EST 2011

Assuming that `src' never refers to GCable memory, this looks fine. You
don't really need to register `tmp', but it's ok to do so.

In general, incorrectly registering variables with the GC can easily
produce a crash, but it rarely creates a memory leak. To track down a
leak, it may be helpful to build Racket with `--enable-backtrace' and
use `dump-memory-stats' to get all the paths to a particular kind of

At Sat, 01 Jan 2011 15:57:53 +0100, gabor papp wrote:
> We are experiencing some small memory leaks in Fluxus, and I am 
> wondering if the garbage collector registration of the following code is 
> right. It should return an array of float values as a scheme vector.
> I read the part on memory allocation in Inside: Racket C API, but I'm 
> not sure how it should be done properly.
> Scheme_Object *FloatsToScheme(float *src, unsigned int size)
> {
>      Scheme_Object *ret=NULL;
>      Scheme_Object *tmp=NULL;
>      MZ_GC_DECL_REG(2);
>      MZ_GC_VAR_IN_REG(0, ret);
>      MZ_GC_VAR_IN_REG(1, tmp);
>      MZ_GC_REG();
>      ret = scheme_make_vector(size, scheme_void);
>      for (unsigned int n=0; n<size; n++)
>      {
>          tmp=scheme_make_double(src[n]);
>          SCHEME_VEC_ELS(ret)[n]=tmp;
>      }
>      MZ_GC_UNREG();
>      return ret;
> }
> Any help would be greatly appreciated.
> Best,
> Gabor

Posted on the users mailing list.