(let ((pos (make-vec3 0.0 0.0 0.0)))
;; do something
)
;; I expect the finalizer to fire here. Because it's now out of scope
(let ((pos (make-vec3 0.0 0.0 0.0)))
;; do something
(FreeVec3 pos)
)
(define-c-struct Vec3
predicate: vec3?
finalizer: FreeVec3
(float x vec3-get-x vec3-set-x)
(float y vec3-get-y vec3-set-y)
(float z vec3-get-z vec3-set-z))
(define-c (free Vec3) (make-vec3 MakeVec3) (float float float))
Vec3* MakeVec3(float x, float y, float z)
{
Vec3 * v = (Vec3*)malloc(sizeof(Vec3));
v->x = x;
v->y = y;
v->z = z;
return v;}
--
You received this message because you are subscribed to the Google Groups "chibi-scheme" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chibi-scheme...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/chibi-scheme/49a5a205-b378-4297-82f5-133400da8746%40googlegroups.com.
So I'm trying to figure out why the object created by my function does not get freed (via it's finalizer) when the scope exits(let ((pos (make-vec3 0.0 0.0 0.0)))
;; do something
)
;; I expect the finalizer to fire here. Because it's now out of scope
Only when the context is destroyed does the finalizer get called.
Could I just call the finalizer manually at the end of the code block?(let ((pos (make-vec3 0.0 0.0 0.0)))
;; do something(FreeVec3 pos))
(let ((pos (make-vec3 0.0 0.0 0.0)))
#t
)
(gc)
(let ((pos (make-vec3 0.0 0.0 0.0)))
#t
)
(gc)
(let ((pos (make-vec3 0.0 0.0 0.0)))
#t
)
(gc)
Program received signal SIGSEGV, Segmentation fault.
sexp_mark_one (types=0x7ffff4c7b5d0, x=0x7ffff4c855e0) at gc.c:203
203 len = sexp_type_num_slots_of_object(t, x) - 1;
..frame 1(draw)(gc)..frame 2(draw)(gc)... and so on
Hi Vincent and Alex,Thank you for answering. I see what you mean. I'll be doing some further tests on this for me to understand things further.As a follow up question. I tried doing this code just for testing:(let ((pos (make-vec3 0.0 0.0 0.0)))
#t
)
(gc)
(let ((pos (make-vec3 0.0 0.0 0.0)))
#t
)
(gc)
(let ((pos (make-vec3 0.0 0.0 0.0)))
#t
)
(gc)I am getting a segmentation fault after the 3rd call to (gc).