Memory leak in MAKE-INSTANCE 'STANDARD-CLASS
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
New
|
Undecided
|
Unassigned |
Bug Description
SBCL 2.0.10 on Linux.
Discovered by Michael Fiano.
Creating anonymous standard-class instances causes a memory leak even if the instances become immediately unreachable. The below example causes a 60MB increase in dynamic space usage not reclaimable even with a full GC.
----------------
* (sb-ext:gc :full t)
NIL
* (room nil)
Dynamic space usage is: 26,948,112 bytes.
Immobile space usage is: 13,945,920 bytes (26,688 bytes overhead).
Read-only space usage is: 0 bytes.
Static space usage is: 736 bytes.
Control stack usage is: 1,952 bytes.
Binding stack usage is: 640 bytes.
Control and binding stack usage is for the current thread only.
Garbage collection is currently enabled.
* (dotimes (i 100000) (make-instance 'standard-class))
NIL
* (sb-ext:gc :full t)
NIL
* (room nil)
Dynamic space usage is: 84,518,336 bytes.
Immobile space usage is: 26,741,824 bytes (22,592 bytes overhead).
Read-only space usage is: 0 bytes.
Static space usage is: 736 bytes.
Control stack usage is: 1,952 bytes.
Binding stack usage is: 640 bytes.
Control and binding stack usage is for the current thread only.
Garbage collection is currently enabled.
One reason for this state of matters is because the STANDARD-CLASSOID for SLOT-OBJECT holds possibly permanent strong references to all of its subclasses.
For instance, in the below example after creating some anonymous classes, the value of SUBCLASSES in that classoid is a non-weak hash table that holds 12157 elements, therefore keeping all the classoids and their layouts live and contributing to the aforementioned memory leak.
------- ------- ------- ------
CL-USER> (let* ((slot-object-class (find-class 'sb-pcl: :slot-object) )
(slot- object- wrapper (slot-value slot-object-class 'sb-pcl::wrapper))
(slot- object- classoid (slot-value slot-object-wrapper 'sb-pcl: :classoid) ))
(swank: inspect- in-emacs slot-object- classoid) )
#<SB-KERNEL: STANDARD- CLASSOID {1000052D03}> ------- ------ STANDARD- CLASSOID. SUPERCLASSES: NIL TYPE-HASH- VALUE> :COUNT 12157 {1000250603}> :SLOT-CLASS SB-PCL: :SLOT-OBJECT>
-------
The object is a STRUCTURE-OBJECT of type SB-KERNEL:
%BITS: 1387484958
NAME: SB-PCL::SLOT-OBJECT
LAYOUT: #<SB-KERNEL:LAYOUT for SB-PCL::SLOT-OBJECT {50217103}>
STATE: NIL
DIRECT-
SOURCE-LOCATION: NIL
SUBCLASSES: #<HASH-TABLE :TEST EQ :HASH-FUNCTION #<FUNCTION SB-KERNEL:
PCL-CLASS: #<SB-PCL:
OLD-LAYOUTS: NIL