|
Re: [Sbcl-help] Transient classes
From: Christophe Rhodes <csr21@ca...> - 2012-09-29 08:40
|
Fredrik Tolf <fredrik@...> writes:
> I've tried creating a class in a couple of ways that I thought would work,
> and then installing a finalizer function on it to show if it were GC'd,
> but I can't seem to get them to be GC'd whatever I do, even if I hack away
> all the references I've been able to find, including the following
> obviously ugly ways:
>
> (let ((test-class (defclass foo (transient) ())))
> (finalize test-class #'(lambda () (print "foo")))
> (setf (sb-kernel:classoid-cell-pcl-class (sb-kernel:find-classoid-cell 'foo)) nil)
> (sb-mop:remove-direct-subclass (find-class 'transient) test-class))
Well, this seems to be nearly there: if I run
(let ((c (let ((test-class (defclass foo (transient) ())))
(finalize test-class #'(lambda () (print "foo")))
(setf (sb-kernel:classoid-cell-pcl-class (sb-kernel:find-classoid-cell 'foo)) nil)
(sb-mop:remove-direct-subclass (find-class 'transient) test-class))))
(dotimes (i 3)
(gc :full t))
(sb-vm::map-referencing-objects #'print :dynamic c))
then I get as output
#<SB-KERNEL:STANDARD-CLASSOID FOO>
(#<STANDARD-CLASS FOO> (24 . #<CLOSURE # {100295C189}>))
The first of these is obvious, I guess: we'd need an extra
(setf (sb-kernel:classoid-pcl-class (sb-kernel:find-classoid 'foo)) nil)
to remove the reference from the classoid (which raises the question of
why the classoid and the classoid-cell both need a reference...
The second is more problematic; I couldn't convince myself that it came
from a real reference, and MAP-REFERENCING-OBJECTS isn't reliable enough
to do a fine dissection (adding the clearing of CLASSOID-PCL-CLASS made
the other printed reference go away). On the other hand, I wasn't
getting the finalization message printed either, so more investigation
is needed.
Cheers,
Christophe
|
| Thread | Author | Date | |
|---|---|---|---|
| [Sbcl-help] Transient classes | Fredrik Tolf <fredrik@do...> |
|
|
|
|
|
|