From be6e222d8d6f0005ea7198d0d3a638eb5f8779ff Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Wed, 24 Sep 2014 10:14:38 -0700 Subject: [PATCH] Fixed: memory leak in CPColorWell --- AppKit/CPColorWell.j | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/AppKit/CPColorWell.j b/AppKit/CPColorWell.j index 8d8132f3a..15fa5343b 100644 --- a/AppKit/CPColorWell.j +++ b/AppKit/CPColorWell.j @@ -86,14 +86,12 @@ var _CPColorWellDidBecomeExclusiveNotification = @"_CPColorWellDidBecomeExclusiv _active = NO; _color = [CPColor whiteColor]; [self setBordered:YES]; - - [self _registerForNotifications]; } return self; } -- (void)_registerForNotifications +- (void)_registerNotifications { var defaultCenter = [CPNotificationCenter defaultCenter]; @@ -110,6 +108,22 @@ var _CPColorWellDidBecomeExclusiveNotification = @"_CPColorWellDidBecomeExclusiv object:[CPColorPanel sharedColorPanel]]; } +- (void)_removeNotifications +{ + var defaultCenter = [CPNotificationCenter defaultCenter]; + + [defaultCenter + removeObserver:self + name:_CPColorWellDidBecomeExclusiveNotification + object:nil]; + + [defaultCenter + removeObserver:self + name:CPWindowWillCloseNotification + object:[CPColorPanel sharedColorPanel]]; + +} + /*! Sets whether the color well is bordered. */ @@ -312,6 +326,28 @@ var _CPColorWellDidBecomeExclusiveNotification = @"_CPColorWellDidBecomeExclusiv [contentBorderView setBackgroundColor:[self currentValueForThemeAttribute:@"content-border-color"]]; } + +#pragma mark - +#pragma mark Observers method + +- (void)_addObservers +{ + if (_isObserving) + return; + + [super _addObservers]; + [self _registerNotifications]; +} + +- (void)_removeObservers +{ + if (!_isObserving) + return; + + [super _removeObservers]; + [self _removeNotifications]; +} + @end @implementation CPColorWellValueBinder : CPBinder @@ -363,8 +399,6 @@ var CPColorWellColorKey = "CPColorWellColorKey", _active = NO; _color = [aCoder decodeObjectForKey:CPColorWellColorKey]; [self setBordered:[aCoder decodeBoolForKey:CPColorWellBorderedKey]]; - - [self _registerForNotifications]; } return self;