Opened 9 years ago

Last modified 8 years ago

#762 new defect

Anonymous classes are never garbage collected

Reported by: wws Owned by:
Priority: normal Milestone:
Component: Runtime (threads, GC) Version: trunk
Keywords: Cc:


Anonymous classes created with ensure-class are held in the direct-subclasses lists of their superclasses (usually standard-class). If given a name, even a gensym'd name, they're also held in the %find-classes% hash table. The superclasses list should be a population and %find-classes% should be weak on value.

Additionally, the %wrapper-cpl-bits slot of a class-wrapper contains a bit vector as large as the maximum %wrapper-class-ordinal of all its transitive superclasses. This was apparently a failed attempt at optimizing typep. Gary said at today's meeting that the ordinal is limited to 1,000,000, which limits the total numbr of classes in an image. We should get rid of this optimization.

I found both of these because my application was consing lots of anonymous classes, and after running for a week there were 500 megabytes of bit vectors.

Change History (3)

comment:1 Changed 9 years ago by wws

Er... %find-classes% should be weak on key.

comment:2 Changed 9 years ago by wws

  • Component changed from IDE to Runtime (threads, GC)

comment:3 Changed 8 years ago by gb

I'm not 100% sure either way, but I'm not sure that I agree that references to anonymous classes "should be" weak. It's true that the classes might be GCed if all references to them were weak, but I wonder how this is different from someone saying "all lists should be weak lists so that their component CONSes can be GCed if there are no strong references to them." Applied to CONSes, the idea that references between objects are implicitly weak doesn't make much sense. Why does it make sense to apply this idea to CLASSes ?

I can't think of anything in CLHS or AMOP that that encourages this assumption. (It's the nature of "weakness" that it's hard to detect, so I can't think of anything that says that references within the class heirarchy couldn't be weak, either.)

If we were to say "inter-class references could be weak, and that might allow anonymous classes to be GCed while still in the class heirarchy, and that might be a good thing", I'd probably agree that that could be a good thing, but would also want to weigh the cost (potentially maintaining CLASS-DIRECT-{SUPER,SUB}CLASSES as weak lists.)

Note: See TracTickets for help on using tickets.