Subject: | Object::FromData::Hash leaks and breaks on key reuse |
Object::FromData::Hash will never clean up the subs it creates or the hash data stored in it. The subs it creates close over the hash directly, so they will keep the hash data alive indefinitely. It also reuses class names if the keys match, so creating a second object with the same keys will issue warnings, and break any existing object.
If you are going to reuse class names, then the subs created need to access data though the object rather than close over the hash. This would still result in leaving the subs around for old objects. You would also want to either skip regenerating subs, or silence the warnings for overwriting them.
The code could also be changed to always use unique class names, and then a DESTROY could clean up the subs.