opscode/chef — pull request #722 by danielsdeleo (2013-04-18 20:06:55+00:00)
Title: Chef 3432 Fix memory leak w/ LWRP class creation

To maintain compatible behavior with the json gem and "json_class" keys without defining arbitrary symbols base on user input, we introduced a class name lookup in `Chef::JSONCompat`. For most cases, it's pretty simple, but for resources, we need to contend with LWRPs and other cases where users define resource classes that are not known beforehand. To accomplish this, `Chef::Resource` maintains a list of all subclasses. There are two bugs with the current implementation:

1. Subclasses of subclasses not tracked correctly. The class list is maintained as a class instance variable, so subclasses of subclasses are added to a list on the intermediate class. Switching to a class variable fixes this behavior.
2. Old LWRP resource classes are not removed from the list when replaced. The list of subclasses grows boundlessly as LWRP resource classes get redefined on each chef client run. We already detect when we're overriding a LWRP class, so we just need to remove the old class from the list.