Skip to content

Commit 53d92fb

Browse files
committed
Cleanup the views when the repository window closes and stop memory leaks.
- make sure to remove themselves from KV and notification center observers - add the PBWebHistoryController to PBHistoryController so it can be told to close - replaced the -removeView methods with -closeView (-removeView was not being used) - clear any obj-c objects set in web scripting objects This last item seems to be the reason that the web controllers and the current commit did not get collected which then held the repository document from being collected as well.
1 parent a849424 commit 53d92fb

13 files changed

+123
-98
lines changed

PBGitCommitController.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ - (void)awakeFromNib
6464
[unstagedFilesController setAutomaticallyRearrangesObjects:NO];
6565
}
6666

67-
- (void)removeView
67+
- (void)closeView
6868
{
6969
[webController closeView];
7070
}

PBGitHistoryController.h

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#import "PBCollapsibleSplitView.h"
1414

1515
@class PBGitSidebarController;
16+
@class PBWebHistoryController;
1617
@class PBGitGradientBarView;
1718
@class PBRefController;
1819
@class QLPreviewPanel;
@@ -28,6 +29,7 @@
2829
NSArray *currentFileBrowserSelectionPath;
2930
IBOutlet PBCommitList* commitList;
3031
IBOutlet PBCollapsibleSplitView *historySplitView;
32+
IBOutlet PBWebHistoryController *webHistoryController;
3133
QLPreviewPanel* previewPanel;
3234

3335
IBOutlet PBGitGradientBarView *upperToolbarView;

PBGitHistoryController.m

+16-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
#import "PBGitHistoryController.h"
10+
#import "PBWebHistoryController.h"
1011
#import "CWQuickLook.h"
1112
#import "PBGitGrapher.h"
1213
#import "PBGitRevisionCell.h"
@@ -415,17 +416,26 @@ - (BOOL) hasNonlinearPath
415416
return [commitController filterPredicate] || [[commitController sortDescriptors] count] > 0;
416417
}
417418

418-
- (void) removeView
419+
- (void)closeView
419420
{
420421
float position = [[[historySplitView subviews] objectAtIndex:0] frame].size.height;
421422
[[NSUserDefaults standardUserDefaults] setFloat:position forKey:@"PBGitSplitViewPosition"];
422423
[[NSUserDefaults standardUserDefaults] synchronize];
423-
[webView close];
424-
[commitController removeObserver:self forKeyPath:@"selection"];
425-
[treeController removeObserver:self forKeyPath:@"selection"];
426-
[repository removeObserver:self forKeyPath:@"currentBranch"];
427424

428-
[super removeView];
425+
if (commitController) {
426+
[commitController removeObserver:self forKeyPath:@"selection"];
427+
[commitController removeObserver:self forKeyPath:@"arrangedObjects.@count"];
428+
[treeController removeObserver:self forKeyPath:@"selection"];
429+
430+
[repository.revisionList removeObserver:self forKeyPath:@"isUpdating"];
431+
[repository.revisionList removeObserver:self forKeyPath:@"updatedGraph"];
432+
[repository removeObserver:self forKeyPath:@"currentBranch"];
433+
[repository removeObserver:self forKeyPath:@"refs"];
434+
}
435+
436+
[webHistoryController closeView];
437+
438+
[super closeView];
429439
}
430440

431441
#pragma mark Table Column Methods

PBGitHistoryView.xib

+48-81
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.10">
33
<data>
44
<int key="IBDocument.SystemTarget">1050</int>
5-
<string key="IBDocument.SystemVersion">10C540</string>
6-
<string key="IBDocument.InterfaceBuilderVersion">740</string>
7-
<string key="IBDocument.AppKitVersion">1038.25</string>
8-
<string key="IBDocument.HIToolboxVersion">458.00</string>
5+
<string key="IBDocument.SystemVersion">10F569</string>
6+
<string key="IBDocument.InterfaceBuilderVersion">762</string>
7+
<string key="IBDocument.AppKitVersion">1038.29</string>
8+
<string key="IBDocument.HIToolboxVersion">461.00</string>
99
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
1010
<bool key="EncodedWithXMLCoder">YES</bool>
1111
<object class="NSArray" key="dict.sortedKeys">
@@ -15,8 +15,8 @@
1515
</object>
1616
<object class="NSMutableArray" key="dict.values">
1717
<bool key="EncodedWithXMLCoder">YES</bool>
18-
<string>740</string>
19-
<string>740</string>
18+
<string>762</string>
19+
<string>762</string>
2020
</object>
2121
</object>
2222
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
@@ -25,8 +25,8 @@
2525
</object>
2626
<object class="NSArray" key="IBDocument.PluginDependencies">
2727
<bool key="EncodedWithXMLCoder">YES</bool>
28-
<string>com.apple.WebKitIBPlugin</string>
2928
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
29+
<string>com.apple.WebKitIBPlugin</string>
3030
</object>
3131
<object class="NSMutableDictionary" key="IBDocument.Metadata">
3232
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -436,7 +436,7 @@
436436
<string key="NSColorName">controlBackgroundColor</string>
437437
<object class="NSColor" key="NSColor" id="827382333">
438438
<int key="NSColorSpace">3</int>
439-
<bytes key="NSWhite">MC42NjY2NjY2ODY1AA</bytes>
439+
<bytes key="NSWhite">MC42NjY2NjY2NjY3AA</bytes>
440440
</object>
441441
</object>
442442
<object class="NSColor" key="NSTextColor" id="57062640">
@@ -1906,6 +1906,14 @@
19061906
</object>
19071907
<int key="connectionID">398</int>
19081908
</object>
1909+
<object class="IBConnectionRecord">
1910+
<object class="IBOutletConnection" key="connection">
1911+
<string key="label">webHistoryController</string>
1912+
<reference key="source" ref="1001"/>
1913+
<reference key="destination" ref="568231003"/>
1914+
</object>
1915+
<int key="connectionID">402</int>
1916+
</object>
19091917
</object>
19101918
<object class="IBMutableOrderedSet" key="objectRecords">
19111919
<object class="NSArray" key="orderedObjects">
@@ -2686,7 +2694,7 @@
26862694
</object>
26872695
</object>
26882696
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
2689-
<string>{{463, 486}, {852, 432}}</string>
2697+
<string>{{9, 486}, {852, 432}}</string>
26902698
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
26912699
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
26922700
<object class="NSMutableDictionary">
@@ -2722,7 +2730,7 @@
27222730
</object>
27232731
</object>
27242732
<nil key="sourceID"/>
2725-
<int key="maxID">398</int>
2733+
<int key="maxID">402</int>
27262734
</object>
27272735
<object class="IBClassDescriber" key="IBDocument.Classes">
27282736
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -2842,14 +2850,15 @@
28422850
<string>selectedBranchFilterItem</string>
28432851
<string>treeController</string>
28442852
<string>upperToolbarView</string>
2853+
<string>webHistoryController</string>
28452854
<string>webView</string>
28462855
</object>
28472856
<object class="NSMutableArray" key="dict.values">
28482857
<bool key="EncodedWithXMLCoder">YES</bool>
28492858
<string>NSButton</string>
28502859
<string>NSButton</string>
28512860
<string>NSArrayController</string>
2852-
<string>NSTableView</string>
2861+
<string>PBCommitList</string>
28532862
<string>NSOutlineView</string>
28542863
<string>PBCollapsibleSplitView</string>
28552864
<string>NSButton</string>
@@ -2861,6 +2870,7 @@
28612870
<string>NSButton</string>
28622871
<string>NSTreeController</string>
28632872
<string>PBGitGradientBarView</string>
2873+
<string>PBWebHistoryController</string>
28642874
<string>id</string>
28652875
</object>
28662876
</object>
@@ -2980,19 +2990,13 @@
29802990
<string>commitController</string>
29812991
<string>commitList</string>
29822992
<string>historyController</string>
2983-
<string>pullItem</string>
2984-
<string>pushItem</string>
2985-
<string>rebaseItem</string>
29862993
</object>
29872994
<object class="NSMutableArray" key="dict.values">
29882995
<bool key="EncodedWithXMLCoder">YES</bool>
29892996
<string>NSPopUpButton</string>
29902997
<string>NSArrayController</string>
29912998
<string>PBCommitList</string>
29922999
<string>PBGitHistoryController</string>
2993-
<string>KBPopUpToolbarItem</string>
2994-
<string>KBPopUpToolbarItem</string>
2995-
<string>KBPopUpToolbarItem</string>
29963000
</object>
29973001
</object>
29983002
<object class="IBClassDescriptionSource" key="sourceIdentifier">
@@ -3476,69 +3480,6 @@
34763480
<string key="minorKey">Foundation.framework/Headers/NSURLDownload.h</string>
34773481
</object>
34783482
</object>
3479-
<object class="IBPartialClassDescription">
3480-
<string key="className">NSObject</string>
3481-
<object class="IBClassDescriptionSource" key="sourceIdentifier">
3482-
<string key="majorKey">IBFrameworkSource</string>
3483-
<string key="minorKey">ImageKit.framework/Headers/IKImageBrowserView.h</string>
3484-
</object>
3485-
</object>
3486-
<object class="IBPartialClassDescription">
3487-
<string key="className">NSObject</string>
3488-
<object class="IBClassDescriptionSource" key="sourceIdentifier">
3489-
<string key="majorKey">IBFrameworkSource</string>
3490-
<string key="minorKey">ImageKit.framework/Headers/IKSaveOptions.h</string>
3491-
</object>
3492-
</object>
3493-
<object class="IBPartialClassDescription">
3494-
<string key="className">NSObject</string>
3495-
<object class="IBClassDescriptionSource" key="sourceIdentifier">
3496-
<string key="majorKey">IBFrameworkSource</string>
3497-
<string key="minorKey">ImageKit.framework/Headers/ImageKitDeprecated.h</string>
3498-
</object>
3499-
</object>
3500-
<object class="IBPartialClassDescription">
3501-
<string key="className">NSObject</string>
3502-
<object class="IBClassDescriptionSource" key="sourceIdentifier">
3503-
<string key="majorKey">IBFrameworkSource</string>
3504-
<string key="minorKey">PDFKit.framework/Headers/PDFDocument.h</string>
3505-
</object>
3506-
</object>
3507-
<object class="IBPartialClassDescription">
3508-
<string key="className">NSObject</string>
3509-
<object class="IBClassDescriptionSource" key="sourceIdentifier">
3510-
<string key="majorKey">IBFrameworkSource</string>
3511-
<string key="minorKey">PDFKit.framework/Headers/PDFView.h</string>
3512-
</object>
3513-
</object>
3514-
<object class="IBPartialClassDescription">
3515-
<string key="className">NSObject</string>
3516-
<object class="IBClassDescriptionSource" key="sourceIdentifier">
3517-
<string key="majorKey">IBFrameworkSource</string>
3518-
<string key="minorKey">QuartzComposer.framework/Headers/QCCompositionParameterView.h</string>
3519-
</object>
3520-
</object>
3521-
<object class="IBPartialClassDescription">
3522-
<string key="className">NSObject</string>
3523-
<object class="IBClassDescriptionSource" key="sourceIdentifier">
3524-
<string key="majorKey">IBFrameworkSource</string>
3525-
<string key="minorKey">QuartzComposer.framework/Headers/QCCompositionPickerView.h</string>
3526-
</object>
3527-
</object>
3528-
<object class="IBPartialClassDescription">
3529-
<string key="className">NSObject</string>
3530-
<object class="IBClassDescriptionSource" key="sourceIdentifier">
3531-
<string key="majorKey">IBFrameworkSource</string>
3532-
<string key="minorKey">QuartzFilters.framework/Headers/QuartzFilterManager.h</string>
3533-
</object>
3534-
</object>
3535-
<object class="IBPartialClassDescription">
3536-
<string key="className">NSObject</string>
3537-
<object class="IBClassDescriptionSource" key="sourceIdentifier">
3538-
<string key="majorKey">IBFrameworkSource</string>
3539-
<string key="minorKey">QuickLookUI.framework/Headers/QLPreviewPanel.h</string>
3540-
</object>
3541-
</object>
35423483
<object class="IBPartialClassDescription">
35433484
<string key="className">NSObject</string>
35443485
<object class="IBClassDescriptionSource" key="sourceIdentifier">
@@ -3869,13 +3810,14 @@
38693810
</object>
38703811
</object>
38713812
<int key="IBDocument.localizationMode">0</int>
3813+
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaFramework</string>
38723814
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencies">
38733815
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.macosx</string>
38743816
<integer value="1050" key="NS.object.0"/>
38753817
</object>
38763818
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults">
38773819
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.macosx</string>
3878-
<integer value="1060" key="NS.object.0"/>
3820+
<integer value="1050" key="NS.object.0"/>
38793821
</object>
38803822
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies">
38813823
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3</string>
@@ -3884,5 +3826,30 @@
38843826
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
38853827
<string key="IBDocument.LastKnownRelativeProjectPath">GitX.xcodeproj</string>
38863828
<int key="IBDocument.defaultPropertyAccessControl">3</int>
3829+
<object class="NSMutableDictionary" key="IBDocument.LastKnownImageSizes">
3830+
<bool key="EncodedWithXMLCoder">YES</bool>
3831+
<object class="NSArray" key="dict.sortedKeys">
3832+
<bool key="EncodedWithXMLCoder">YES</bool>
3833+
<string>AddBranchTemplate</string>
3834+
<string>AddLabelTemplate</string>
3835+
<string>CherryPickTemplate</string>
3836+
<string>DetailViewTemplate</string>
3837+
<string>MergeTemplate</string>
3838+
<string>NSPathTemplate</string>
3839+
<string>NSQuickLookTemplate</string>
3840+
<string>RebaseTemplate</string>
3841+
</object>
3842+
<object class="NSMutableArray" key="dict.values">
3843+
<bool key="EncodedWithXMLCoder">YES</bool>
3844+
<string>{20, 12}</string>
3845+
<string>{23, 12}</string>
3846+
<string>{18.5143, 12.3429}</string>
3847+
<string>{17, 17}</string>
3848+
<string>{16.4571, 12.3429}</string>
3849+
<string>{16, 9}</string>
3850+
<string>{19, 11}</string>
3851+
<string>{16.4571, 13.3714}</string>
3852+
</object>
3853+
</object>
38873854
</data>
38883855
</archive>

PBGitSidebarController.m

+11
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@ - (void)awakeFromNib
5959
[self selectCurrentBranch];
6060
}
6161

62+
- (void)closeView
63+
{
64+
[historyViewController closeView];
65+
[commitViewController closeView];
66+
67+
[repository removeObserver:self forKeyPath:@"currentBranch"];
68+
[repository removeObserver:self forKeyPath:@"branches"];
69+
70+
[super closeView];
71+
}
72+
6273
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
6374
{
6475
if ([@"currentBranchChange" isEqualToString:context]) {

PBGitWindowController.m

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ - (void)windowWillClose:(NSNotification *)notification
3333
NSLog(@"Window will close!");
3434

3535
if (sidebarController)
36-
[sidebarController removeView];
36+
[sidebarController closeView];
37+
38+
if (contentController)
39+
[contentController removeObserver:self forKeyPath:@"status"];
3740
}
3841

3942
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem

PBGraphCellInfo.m

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ - (id)initWithPosition:(int)p andLines:(struct PBGitGraphLine *)l
1919
return self;
2020
}
2121

22+
- (void)setLines:(struct PBGitGraphLine *)l
23+
{
24+
free(lines);
25+
lines = l;
26+
}
27+
2228
-(void) finalize
2329
{
2430
free(lines);

PBViewController.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@
2525

2626
- (id)initWithRepository:(PBGitRepository *)theRepository superController:(PBGitWindowController *)controller;
2727

28-
/* removeView is called whenever the view is removed, either to be swapped
29-
* with a different view, or when the repository window will be destroyed
30-
*/
31-
- (void) removeView;
28+
/* closeView is called when the repository window will be closed */
29+
- (void)closeView;
3230

3331
/* Updateview is called every time it is loaded into the main view */
3432
- (void) updateView;

PBViewController.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ - (id)initWithRepository:(PBGitRepository *)theRepository superController:(PBGit
2727
return self;
2828
}
2929

30-
- (void)removeView
30+
- (void)closeView
3131
{
3232
[self unbind:@"repository"];
3333
if (hasViewLoaded)

PBWebChangesController.m

+9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ - (void) awakeFromNib
2424
[cachedFilesController addObserver:self forKeyPath:@"selection" options:0 context:@"cachedFileSelected"];
2525
}
2626

27+
- (void)closeView
28+
{
29+
[[self script] removeWebScriptKey:@"Index"];
30+
[unstagedFilesController removeObserver:self forKeyPath:@"selection"];
31+
[cachedFilesController removeObserver:self forKeyPath:@"selection"];
32+
33+
[super closeView];
34+
}
35+
2736
- (void) didLoad
2837
{
2938
[[self script] setValue:controller.index forKey:@"Index"];

0 commit comments

Comments
 (0)