From 3dd63854404b31cdf3a2b2d1ce3f18507af9664f Mon Sep 17 00:00:00 2001 From: Pieter de Bie Date: Wed, 26 Nov 2008 17:02:23 +0100 Subject: [PATCH] Fix memory leaks --- PBGitCommitController.m | 5 +++++ PBGitHistoryController.m | 4 ++++ PBGitRepository.m | 5 +++++ PBGitWindowController.m | 6 ++++++ PBViewController.m | 1 + PBWebController.h | 1 + PBWebController.m | 6 ++++++ PBWebHistoryController.m | 6 ++++++ 8 files changed, 34 insertions(+) diff --git a/PBGitCommitController.m b/PBGitCommitController.m index fe46670..8e01c75 100644 --- a/PBGitCommitController.m +++ b/PBGitCommitController.m @@ -30,6 +30,11 @@ [cachedFilesController setSortDescriptors:[NSArray arrayWithObject: [[NSSortDescriptor alloc] initWithKey:@"path" ascending:true]]]; } +- (void) removeView +{ + [webController closeView]; + [super finalize]; +} - (void) setAmend:(BOOL)newAmend { diff --git a/PBGitHistoryController.m b/PBGitHistoryController.m index 64758bb..fea0bb5 100644 --- a/PBGitHistoryController.m +++ b/PBGitHistoryController.m @@ -190,6 +190,10 @@ - (void) removeView { [webView close]; + [commitController removeObserver:self forKeyPath:@"selection"]; + [treeController removeObserver:self forKeyPath:@"selection"]; + [repository removeObserver:self forKeyPath:@"currentBranch"]; + [super removeView]; } diff --git a/PBGitRepository.m b/PBGitRepository.m index 4dd33f8..a5d3a92 100644 --- a/PBGitRepository.m +++ b/PBGitRepository.m @@ -375,4 +375,9 @@ NSString* PBGitRepositoryErrorDomain = @"GitXErrorDomain"; return nil; } +- (void) finalize +{ + NSLog(@"Dealloc of repository"); + [super finalize]; +} @end diff --git a/PBGitWindowController.m b/PBGitWindowController.m index 7495b78..6cf01b5 100644 --- a/PBGitWindowController.m +++ b/PBGitWindowController.m @@ -33,6 +33,11 @@ return self; } +- (void)windowWillClose:(NSNotification *)notification +{ + [viewController removeView]; +} + - (void) setSelectedViewIndex: (int) i { selectedViewIndex = i; @@ -70,6 +75,7 @@ - (void)awakeFromNib { + [[self window] setDelegate:self]; [[self window] setAutorecalculatesContentBorderThickness:NO forEdge:NSMinYEdge]; [[self window] setContentBorderThickness:35.0f forEdge:NSMinYEdge]; [self showHistoryView:nil]; diff --git a/PBViewController.m b/PBViewController.m index 971eb36..38d9af1 100644 --- a/PBViewController.m +++ b/PBViewController.m @@ -27,6 +27,7 @@ - (void) removeView { + [self unbind:@"repository"]; [[self view] removeFromSuperview]; // remove the current view } diff --git a/PBWebController.h b/PBWebController.h index 5921a11..2715e5e 100644 --- a/PBWebController.h +++ b/PBWebController.h @@ -25,4 +25,5 @@ @property (retain) id repository; - (WebScriptObject *) script; +- (void) closeView; @end diff --git a/PBWebController.m b/PBWebController.m index 3ad0176..e5b76ec 100644 --- a/PBWebController.m +++ b/PBWebController.m @@ -35,6 +35,12 @@ return [view windowScriptObject]; } +- (void) closeView +{ + if (view) + [view close]; +} + # pragma mark Delegate methods - (void) webView:(id) v didFinishLoadForFrame:(id) frame diff --git a/PBWebHistoryController.m b/PBWebHistoryController.m index e3f5575..1b49fa4 100644 --- a/PBWebHistoryController.m +++ b/PBWebHistoryController.m @@ -108,4 +108,10 @@ contextMenuItemsForElement:(NSDictionary *)element return [historyController valueForKeyPath:[@"repository.config." stringByAppendingString:config]]; } +- (void) finalize +{ + [historyController removeObserver:self forKeyPath:@"webCommit"]; + [super finalize]; +} + @end