jeffp / enumerated_attribute

Easy enum for your models, objects and views
MIT License
190 stars 64 forks source link

Leaks memory when cache_classes == false #20

Open brandonbloom opened 13 years ago

brandonbloom commented 13 years ago

I recently added enumerated_attribute to my Rails 3 project and it causes it to leak about ~10M of memory on every request.

jensb commented 13 years ago

Seems to be the same problem as AASM has: https://github.com/rubyist/aasm/issues/31

iceboundflame commented 13 years ago

This is a huge problem! It makes development pretty painful, grinding to a halt after testing every so often.

markiz commented 13 years ago

I guess that's due to an excessive use of to_sym calls, since symbols aren't garbage collected.

brandonbloom commented 13 years ago

to_sym does in fact leak, but that shouldn't be an issue if you only call it on a well-known limited-set of strings. It shouldn't be called on unvalidated data from untrusted clients, because someone could pass random large strings over and over again until you run out of memory. However, I'm not so sure that's the issue with enumerated_attribute, since ~10M seems oddly consistent. More likely: The entire models object space is being retained somewhere. Anyway, I'm no longer using this library so I am going to unsubscribe from notifications on this issue.

iceboundflame commented 13 years ago

I found a workaround: when developing, use a gem like active_reload to cut down dramatically on the amount of memory leaked under normal usage. This only reloads classes that have changed, with the side effect of the app being much, much faster.

budu commented 12 years ago

This issue is still affecting Rails (with 3.1), leaking aroung 30MB every request on a mid-size project.