Skip to content

Commit

Permalink
Fix memory leaks
Browse files Browse the repository at this point in the history
This changes a bunch of ivars to __weak's, to avoid reference loops.
Furthermore, in PBGitHistoryController, we need to call [webView close],
otherwise some memory will never be freed?
  • Loading branch information
pieter committed Sep 28, 2008
1 parent 95c4bcb commit 1028157
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion PBChangedFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ typedef enum {
@interface PBChangedFile : NSObject {
NSString *path;
BOOL cached;
PBGitRepository *repository;
__weak PBGitRepository *repository;
PBChangedFileStatus status;
}

Expand Down
1 change: 1 addition & 0 deletions PBGitHistoryController.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
IBOutlet NSTreeController* treeController;
IBOutlet NSOutlineView* fileBrowser;
IBOutlet NSTableView* commitList;
IBOutlet id webView;
int selectedTab;

PBGitTree* gitTree;
Expand Down
6 changes: 6 additions & 0 deletions PBGitHistoryController.m
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,10 @@ - (BOOL) hasNonlinearPath
{
return [commitController filterPredicate] || [[commitController sortDescriptors] count] > 0;
}

- (void) removeView
{
[webView close];
[super removeView];
}
@end
16 changes: 13 additions & 3 deletions PBGitHistoryView.xib
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<string key="IBDocument.HIToolboxVersion">352.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
<integer value="3"/>
<integer value="20"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
Expand Down Expand Up @@ -1328,6 +1328,14 @@
</object>
<int key="connectionID">111</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">webView</string>
<reference key="source" ref="1001"/>
<reference key="destination" ref="676796335"/>
</object>
<int key="connectionID">112</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
Expand Down Expand Up @@ -1830,7 +1838,7 @@
</object>
</object>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>{{328, 233}, {852, 432}}</string>
<string>{{423, 120}, {852, 432}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
Expand Down Expand Up @@ -1860,7 +1868,7 @@
</object>
</object>
<nil key="sourceID"/>
<int key="maxID">111</int>
<int key="maxID">112</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
Expand Down Expand Up @@ -1920,13 +1928,15 @@
<string>commitList</string>
<string>fileBrowser</string>
<string>treeController</string>
<string>webView</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>NSArrayController</string>
<string>NSTableView</string>
<string>NSOutlineView</string>
<string>NSTreeController</string>
<string>id</string>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
Expand Down
2 changes: 1 addition & 1 deletion PBGitWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ - (void)changeViewController:(NSInteger)whichViewTag
self.searchController = nil;
[self unbind:@"searchController"];
if ([viewController view] != nil)
[[viewController view] removeFromSuperview]; // remove the current view
[(PBViewController *)viewController removeView];

switch (whichViewTag)
{
Expand Down
8 changes: 4 additions & 4 deletions PBViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
#import "PBGitWindowController.h"

@interface PBViewController : NSViewController {
PBGitRepository *repository;
PBGitWindowController *superController;
__weak PBGitRepository *repository;
__weak PBGitWindowController *superController;
}

@property (readonly) PBGitRepository *repository;
@property (readonly) __weak PBGitRepository *repository;

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

- (void) removeView;
@end
4 changes: 4 additions & 0 deletions PBViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ - (id)initWithRepository:(PBGitRepository *)theRepository superController:(PBGit
return self;
}

- (void) removeView
{
[[self view] removeFromSuperview]; // remove the current view
}
@end

0 comments on commit 1028157

Please sign in to comment.