[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Proper way of making a single-pointer smob
From: |
Sun Yijiang |
Subject: |
Re: Proper way of making a single-pointer smob |
Date: |
Fri, 31 May 2013 11:08:02 +0800 |
Thank you guys, I got it through.
Best,
Yijiang
2013/5/29 Mike Gran <address@hidden>:
>>Hi guys,
>
>
>>I'm using a very simple smob which only carries a pointer in the
>>immediate word. It works fine, but what worries me is that the free
>>function seems never called. Am I doing anything wrong? What's the
>>standard way of making such kind of smob?
>
>
> What you are doing is mostly right, except for this.
>
>
>> model_smob_t = scm_make_smob_type("model", 0); // shall I use zero here?
>
> Your "0" should be sizeof(MyModel*)
>
> But that's not the problem.
>
> The problem is either
> 1. You still have a pointer to the smob somewhere. You need to make
> sure that there are no pointers anywhere to the smob.
> 2. The garbage collector isn't being run. Maybe you never allocate
> enough memory to cause the gc to run. You can fix this by adding
> a "scm_gc()" call just before you program exits to force a garbage
> collection.
> 3. Some versions of Guile have a bug where the last smob defined
> in your program is never freed, even if you've cleared out the
> pointers and called scm_gc.
>
> -Mike