[racket] Freeing FFI resources

From: Eli Barzilay (eli at barzilay.org)
Date: Mon Oct 11 19:07:23 EDT 2010

5 hours ago, Neil Toronto wrote:
> I'd be wary of the bytes/free example: I'd free the bytes ASAP instead 
> of using a finalizer.

That shouldn't be a problem.

> I confused the crap out of Racket's GC by keeping externally-managed
> memory around that was pointed at by Racket-owned objects with
> registered finalizers.

That should work fine.

> (I made sure the external memory was properly atomic, like bytes
> are.)

"Properly atomic" might be an indicationof the problem -- external
memory is invisible to the racket GC, and there is no distinction
between atomic blocks or whatever -- as far as racket knows, it's a
pointer to something it doesn't care about.  So it might be that you
were `malloc'ing memory yourself, and using `atomic' instead of `raw'
(the latter gives you access to plain malloc(), which results in
memory blocks that are GC-invisible).

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the users mailing list.