Skip to content

Commit

Permalink
Merge pull request laullon#164 from ksuther/master
Browse files Browse the repository at this point in the history
Fixed lots of retain cycles which caused memory leaks
  • Loading branch information
laullon committed Feb 28, 2012
2 parents 83307f6 + 94e722b commit 7e21c52
Show file tree
Hide file tree
Showing 36 changed files with 101 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Controller/PBGitResetController.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@protocol PBGitRefish;

@interface PBGitResetController : NSObject {
PBGitRepository *repository;
__unsafe_unretained PBGitRepository *repository;
}
- (id) initWithRepository:(PBGitRepository *) repo;

Expand Down
2 changes: 1 addition & 1 deletion Controller/PBSubmoduleController.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@interface PBSubmoduleController : NSObject {
@private
PBGitRepository *repository;
__unsafe_unretained PBGitRepository *repository;
NSArray *submodules;
}

Expand Down
6 changes: 5 additions & 1 deletion Controller/PBSubmoduleController.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ - (void) reload {
}
}

submodules = loadedSubmodules;
dispatch_async(dispatch_get_main_queue(), ^{
[self willChangeValueForKey:@"submodules"];
submodules = loadedSubmodules;
[self didChangeValueForKey:@"submodules"];
});
});
}

Expand Down
7 changes: 5 additions & 2 deletions GLFileView.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
@class PBGitGradientBarView;

@interface GLFileView : PBWebController <MGScopeBarDelegate> {
IBOutlet PBGitHistoryController* historyController;
IBOutlet MGScopeBar *typeBar;
__unsafe_unretained PBGitHistoryController* historyController;
__unsafe_unretained MGScopeBar *typeBar;
NSMutableArray *groups;
NSString *logFormat;
NSString *diffType;
Expand All @@ -29,6 +29,9 @@
PBGitTree *lastFile;
}

@property(nonatomic, unsafe_unretained) IBOutlet PBGitHistoryController *historyController;
@property(nonatomic, unsafe_unretained) IBOutlet MGScopeBar *typeBar;

- (void)showFile;
- (void)didLoad;
- (NSString *)parseBlame:(NSString *)txt;
Expand Down
2 changes: 2 additions & 0 deletions GLFileView.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ + (NSString *)parseBinaryDiff:(NSString *)txt;

@implementation GLFileView

@synthesize historyController, typeBar;

- (void) awakeFromNib
{
NSString *formatFile = [[NSBundle mainBundle] pathForResource:@"format" ofType:@"html" inDirectory:@"html/views/log"];
Expand Down
4 changes: 3 additions & 1 deletion GitXTextFieldCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@


@interface GitXTextFieldCell : NSTextFieldCell {
IBOutlet id<PBRefContextDelegate> contextMenuDelegate;
__unsafe_unretained id<PBRefContextDelegate> contextMenuDelegate;
}

@property(nonatomic, unsafe_unretained) IBOutlet id<PBRefContextDelegate> contextMenuDelegate;

@end
2 changes: 2 additions & 0 deletions GitXTextFieldCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

@implementation GitXTextFieldCell

@synthesize contextMenuDelegate;

- (NSColor *)highlightColorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
// disables the cell's selection highlight
Expand Down
4 changes: 2 additions & 2 deletions MGScopeBar/MGScopeBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@interface MGScopeBar : NSView {
@private
IBOutlet id <MGScopeBarDelegate, NSObject> delegate; // weak ref.
__unsafe_unretained id <MGScopeBarDelegate, NSObject> delegate; // weak ref.
NSMutableArray *_separatorPositions; // x-coords of separators, indexed by their group-number.
NSMutableArray *_groups; // groups of items.
NSView *_accessoryView; // weak ref since it's a subview.
Expand All @@ -24,7 +24,7 @@
BOOL _smartResizeEnabled; // whether to do our clever collapsing/expanding of buttons when resizing (Smart Resizing).
}

@property(strong,nonatomic) id delegate; // should implement the MGScopeBarDelegate protocol.
@property(unsafe_unretained,nonatomic) IBOutlet id delegate; // should implement the MGScopeBarDelegate protocol.

- (void)reloadData; // causes the scope-bar to reload all groups/items from its delegate.
- (void)sizeToFit; // only resizes vertically to optimum height; does not affect width.
Expand Down
10 changes: 7 additions & 3 deletions PBCommitList.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@
// delegate: PBGitHistoryController
@interface PBCommitList : NSTableView {
IBOutlet WebView* webView;
IBOutlet PBWebHistoryController *webController;
IBOutlet PBGitHistoryController *controller;
IBOutlet PBHistorySearchController *searchController;
__unsafe_unretained PBWebHistoryController *webController;
__unsafe_unretained PBGitHistoryController *controller;
__unsafe_unretained PBHistorySearchController *searchController;

BOOL useAdjustScroll;
NSPoint mouseDownPoint;
}

@property(nonatomic, unsafe_unretained) IBOutlet PBWebHistoryController *webController;
@property(nonatomic, unsafe_unretained) IBOutlet PBGitHistoryController *controller;
@property(nonatomic, unsafe_unretained) IBOutlet PBHistorySearchController *searchController;

@property (readonly) NSPoint mouseDownPoint;
@property (assign) BOOL useAdjustScroll;
@end
1 change: 1 addition & 0 deletions PBCommitList.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

@implementation PBCommitList

@synthesize webController, controller, searchController;
@synthesize mouseDownPoint;
@synthesize useAdjustScroll;

Expand Down
4 changes: 2 additions & 2 deletions PBGitCommit.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extern NSString * const kGitXCommitType;
int timestamp;
char sign;
id lineInfo;
PBGitRepository* repository;
__unsafe_unretained PBGitRepository* repository;
}

+ (PBGitCommit *)commitWithRepository:(PBGitRepository*)repo andSha:(NSString *)newSha;
Expand Down Expand Up @@ -65,6 +65,6 @@ extern NSString * const kGitXCommitType;
@property (readonly) NSString* details;
@property (readonly) PBGitTree* tree;
@property (readonly) NSArray* treeContents;
@property (strong) PBGitRepository* repository;
@property (unsafe_unretained) PBGitRepository* repository;
@property (strong) id lineInfo;
@end
18 changes: 6 additions & 12 deletions PBGitHistoryController.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,12 @@

// Controls the split history view from PBGitHistoryView.xib
@interface PBGitHistoryController : PBViewController PROTOCOL_10_6(NSOutlineViewDelegate){
IBOutlet PBRefController *refController;
IBOutlet NSSearchField *searchField;
IBOutlet NSArrayController* commitController;
IBOutlet NSSearchField *filesSearchField;
IBOutlet NSTreeController* treeController;
IBOutlet NSOutlineView* fileBrowser;
NSArray *currentFileBrowserSelectionPath;
IBOutlet PBCommitList* commitList;
IBOutlet NSSplitView *historySplitView;
IBOutlet PBWebHistoryController *webHistoryController;
QLPreviewPanel* previewPanel;
IBOutlet PBHistorySearchController *searchController;
IBOutlet GLFileView *fileView;

IBOutlet PBGitGradientBarView *upperToolbarView;
Expand All @@ -57,15 +51,15 @@
PBGitCommit *selectedCommitBeforeRefresh;
}

@property (readonly) NSTreeController* treeController;
@property (readonly) NSSplitView *historySplitView;
@property (unsafe_unretained) IBOutlet NSTreeController* treeController;
@property (unsafe_unretained) IBOutlet NSSplitView *historySplitView;
@property (nonatomic,assign) int selectedCommitDetailsIndex;
@property (strong) PBGitCommit *webCommit;
@property (strong) PBGitTree* gitTree;
@property (readonly) NSArrayController *commitController;
@property (readonly) PBRefController *refController;
@property (readonly) PBHistorySearchController *searchController;
@property (readonly) PBCommitList *commitList;
@property (unsafe_unretained) IBOutlet NSArrayController *commitController;
@property (unsafe_unretained) IBOutlet PBRefController *refController;
@property (unsafe_unretained) IBOutlet PBHistorySearchController *searchController;
@property (unsafe_unretained) PBCommitList *commitList;

- (IBAction) setDetailedView:(id)sender;
- (IBAction) setTreeView:(id)sender;
Expand Down
9 changes: 5 additions & 4 deletions PBGitHistoryController.m
Original file line number Diff line number Diff line change
Expand Up @@ -483,11 +483,12 @@ - (void)closeView
{
[self saveSplitViewPosition];

if (commitController) {
[commitController removeObserver:self forKeyPath:@"selection"];
[commitController removeObserver:self forKeyPath:@"arrangedObjects.@count"];
[treeController removeObserver:self forKeyPath:@"selection"];
[commitController removeObserver:self forKeyPath:@"selection"];
[commitController removeObserver:self forKeyPath:@"arrangedObjects.@count"];
[treeController removeObserver:self forKeyPath:@"selection"];

//Only stop these observations if the nib got loaded
if (hasViewLoaded) {
[repository.revisionList removeObserver:self forKeyPath:@"isUpdating"];
[repository removeObserver:self forKeyPath:@"currentBranch"];
[repository removeObserver:self forKeyPath:@"refs"];
Expand Down
2 changes: 1 addition & 1 deletion PBGitHistoryGrapher.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


@interface PBGitHistoryGrapher : NSObject {
id delegate;
__unsafe_unretained id delegate;
NSOperationQueue *currentQueue;

NSMutableSet *searchSHAs;
Expand Down
2 changes: 1 addition & 1 deletion PBGitHistoryList.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@class PBGitHistoryGrapher;

@interface PBGitHistoryList : NSObject {
PBGitRepository *repository;
__unsafe_unretained PBGitRepository *repository;

PBGitRevList *projectRevList;
PBGitRevList *currentRevList;
Expand Down
7 changes: 3 additions & 4 deletions PBGitHistoryList.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,9 @@ - (void) updateHistory

- (void)cleanup
{
if (currentRevList) {
[currentRevList removeObserver:self forKeyPath:@"commits"];
[currentRevList cancel];
}
[currentRevList removeObserver:self forKeyPath:@"commits"];
[currentRevList cancel];

[graphQueue cancelAllOperations];

[repository removeObserver:self forKeyPath:@"currentBranch"];
Expand Down
5 changes: 0 additions & 5 deletions PBGitRepository.m
Original file line number Diff line number Diff line change
Expand Up @@ -1965,9 +1965,4 @@ - (NSString*) parseSymbolicReference:(NSString*) reference
return nil;
}

- (void) finalize
{
//DLog(@"Dealloc of repository");
[super finalize];
}
@end
2 changes: 1 addition & 1 deletion PBGitRevList.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@interface PBGitRevList : NSObject {
NSMutableArray *commits;

PBGitRepository *repository;
__unsafe_unretained PBGitRepository *repository;
PBGitRevSpecifier *currentRev;
BOOL isGraphing;

Expand Down
11 changes: 11 additions & 0 deletions PBGitRevList.mm
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,17 @@ - (void) walkRevisionListWithSpecifier:(PBGitRevSpecifier*)rev

[task terminate];
[task waitUntilExit];

//Nasty hack to work around ARC and bindings getting angry at each other
//Without this some of the view controllers can get released while not on the main thread, which crashes in bindings
__block PBGitRepository *tempRepository = repository;

double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
if ([tempRepository isKindOfClass:[PBGitRepository class]]) {
}
});
}

@end
8 changes: 6 additions & 2 deletions PBGitRevisionCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@
PBGitCommit *objectValue;
PBGraphCellInfo *cellInfo;
NSTextFieldCell *textCell;
IBOutlet PBGitHistoryController *controller;
IBOutlet id<PBRefContextDelegate> contextMenuDelegate;
__unsafe_unretained PBGitHistoryController *controller;
__unsafe_unretained id<PBRefContextDelegate> contextMenuDelegate;
}

@property(nonatomic, unsafe_unretained) IBOutlet PBGitHistoryController *controller;
@property(nonatomic, unsafe_unretained) IBOutlet id<PBRefContextDelegate> contextMenuDelegate;


- (int) indexAtX:(float)x;
- (NSRect) rectAtIndex:(int)index;
- (void) drawLabelAtIndex:(int)index inRect:(NSRect)rect;
Expand Down
1 change: 1 addition & 0 deletions PBGitRevisionCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

@implementation PBGitRevisionCell

@synthesize controller, contextMenuDelegate;

- (id) initWithCoder: (id) coder
{
Expand Down
1 change: 1 addition & 0 deletions PBGitSidebarController.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ - (void)closeView
[commitViewController closeView];
[stashViewController closeView];

[repository removeObserver:self forKeyPath:@"refs"];
[repository removeObserver:self forKeyPath:@"currentBranch"];
[repository removeObserver:self forKeyPath:@"branches"];
[repository removeObserver:self forKeyPath:@"stashController.stashes"];
Expand Down
4 changes: 2 additions & 2 deletions PBHistorySearchController.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ typedef enum historySearchModes {


@interface PBHistorySearchController : NSObject {
PBGitHistoryController *historyController;
__unsafe_unretained PBGitHistoryController *historyController;
NSArrayController *commitController;

PBHistorySearchMode searchMode;
Expand All @@ -38,7 +38,7 @@ typedef enum historySearchModes {
NSPanel *rewindPanel;
}

@property (strong) IBOutlet PBGitHistoryController *historyController;
@property (unsafe_unretained) IBOutlet PBGitHistoryController *historyController;
@property (strong) IBOutlet NSArrayController *commitController;

@property (strong) IBOutlet NSSearchField *searchField;
Expand Down
4 changes: 3 additions & 1 deletion PBQLOutlineView.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#import "PBGitHistoryController.h"

@interface PBQLOutlineView : NSOutlineView {
IBOutlet PBGitHistoryController* controller;
__unsafe_unretained PBGitHistoryController *controller;
}

@property(nonatomic, unsafe_unretained) IBOutlet PBGitHistoryController *controller;

@end
2 changes: 2 additions & 0 deletions PBQLOutlineView.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

@implementation PBQLOutlineView

@synthesize controller;

- initWithCoder: (NSCoder *) coder
{
id a = [super initWithCoder:coder];
Expand Down
4 changes: 3 additions & 1 deletion PBQLTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@


@interface PBQLTextView : NSTextView {
IBOutlet PBGitHistoryController *controller;
__unsafe_unretained PBGitHistoryController *controller;
}

@property(nonatomic, unsafe_unretained) IBOutlet PBGitHistoryController *controller;

@end
2 changes: 2 additions & 0 deletions PBQLTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

@implementation PBQLTextView

@synthesize controller;

- (void) keyDown: (NSEvent *) event
{
if ([[event characters] isEqualToString:@" "]) {
Expand Down
4 changes: 3 additions & 1 deletion PBRefController.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@class PBRefMenuItem;

@interface PBRefController : NSObject <PBRefContextDelegate> {
IBOutlet PBGitHistoryController *historyController;
__unsafe_unretained PBGitHistoryController *historyController;
IBOutlet NSArrayController *commitController;
IBOutlet PBCommitList *commitList;

Expand All @@ -25,6 +25,8 @@
PBGitRef *actRef;
}

@property(nonatomic, unsafe_unretained) IBOutlet PBGitHistoryController *historyController;

- (void) fetchRemote:(PBRefMenuItem *)sender;
- (void) pullRemote:(PBRefMenuItem *)sender;
- (void) pushUpdatesToRemote:(PBRefMenuItem *)sender;
Expand Down
2 changes: 2 additions & 0 deletions PBRefController.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

@implementation PBRefController

@synthesize historyController;

-(void)dealloc
{
actDropInfo = Nil;
Expand Down
2 changes: 1 addition & 1 deletion PBStashController.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@interface PBStashController : NSObject {
@private
PBGitRepository *repository;
__unsafe_unretained PBGitRepository *repository;
}

- (id) initWithRepository:(PBGitRepository *) repo;
Expand Down
Loading

0 comments on commit 7e21c52

Please sign in to comment.