rubymotion-community / BubbleWrap

Cocoa wrappers and helpers for RubyMotion (Ruby for iOS and OS X) - Making Cocoa APIs more Ruby like, one API at a time. Fork away and send your pull requests
Other
1.18k stars 208 forks source link

Fix memory leak in eventable __events__ hash #398

Closed jsteinberg closed 10 years ago

jsteinberg commented 10 years ago

Based off of a current leak in rubymotion(http://hipbyte.myjetbrains.com/youtrack/issue/RM-534), I have fixed a leak in the eventable module. Creating the hash of events as it was

@__events__ ||= Hash.new { |h,k| h[k] = [] }

will create a circular retain, and the object will never be deallocated. Removing the proc after Hash.new resolves the issue.

clayallsopp commented 10 years ago

Wow, that's interesting. I'm fine with keeping this workaround long term, since it's a pretty simple refactor. Thanks!