[gambit-list] Gambit FFI reference counting

Phil Dawes pdawes at users.sf.net
Thu Feb 8 16:48:43 EST 2007

The trickiest thing I found writing Gambit FFI code[1] was managing memory.
After flailing around a bit scratching my head over memory leaks and 
crashes I found the best technique was to check the reference counts of 
objects as much as possible. Gambit doesn't appear to have a function to 
peek the refcount of a "STILL" allocated object, so I created a simple 
one in my code:

int _peek_refcount(___SCMOBJ s){
#define ___STILL_BODY_OFS 6
    return ___UNTAG(s)[___BODY_OFS - ___STILL_BODY_OFS + 

I then littered the code with assert calls. e.g:

assert(1 == _peek_refcount(myobj));

Hope this helps somebody,



More information about the Gambit-list mailing list