diff --git a/Butter/BTRControl.m b/Butter/BTRControl.m index 8cfeb9c..e299518 100644 --- a/Butter/BTRControl.m +++ b/Butter/BTRControl.m @@ -421,6 +421,48 @@ - (void)sendActionsForControlEvents:(BTRControlEvents)events { } } +- (void)removeFromSuperview { + // free Block and trackArea + [super removeFromSuperview]; + if (self.trackingArea) { + self.needsTrackingArea= NO; + [self removeTrackingArea:self.trackingArea]; + self.trackingArea = nil; + } + + for (BTRControlAction *action in self.actions) { + if (action.block) { + action.block = nil; + } + } + if (self.actions.count) { + [self.actions removeAllObjects]; + } + if (self.content.count) { + [self.content removeAllObjects]; + } +} + +- (void)dealloc { + // free Block and trackArea + if (self.trackingArea) { + self.needsTrackingArea= NO; + [self removeTrackingArea:self.trackingArea]; + self.trackingArea = nil; + } + for (BTRControlAction *action in self.actions) { + if (action.block) { + action.block = nil; + } + } + if (self.actions.count) { + [self.actions removeAllObjects]; + } + if (self.content.count) { + [self.content removeAllObjects]; + } +} + @end @implementation BTRControlContent {