Comment 8 for bug 1903413

Douglas Katzman (dougk) wrote :

I have to disagree that nuke-package is useful. The issue of object retention is entirely about the type system and nothing but that. A simple test case proves that deleted packages don't accidentally retain objects, but for the type system's hierarchy:

(make-package "TEST" :use '("CL" "SB-EXT"))
(in-package test)
(defstruct test x)
(defvar *testvar* (cons 1 2))
(defun testfun (x) x)
(deftype testtype () 'integer)

(defvar cl-user::*wps*
  (list (make-weak-pointer '*testvar*) ; name of var
        (make-weak-pointer *testvar*) ; value of the name
        (make-weak-pointer 'testfun) ; name of fun
        (make-weak-pointer #'testfun) ; value of the name
        (make-weak-pointer 'make-test))) ; structure ctor

(in-package cl-user)
(delete-package "TEST")
(gc :full t)
* *wps*
(#<broken weak pointer> #<broken weak pointer> #<broken weak pointer>
 #<broken weak pointer> #<weak pointer: #:MAKE-TEST>)

#:MAKE-TEST was retained only because type named #:TEST was retained, which was retained because it is the name of a classoid; a structure-classoid has a defstruct-description, which points to its constructor function, and so on and so on. Again, it is entirely the fault of the MOP -
* (car(sb-mop::class-direct-subclasses(find-class'structure-object)))
#<STRUCTURE-CLASS #:TEST>