Skip to content

Commit

Permalink
Merge pull request AlanQuatermain#105 from augard/master
Browse files Browse the repository at this point in the history
Fixed ARC leaks
  • Loading branch information
AlanQuatermain committed Jan 3, 2012
2 parents 4072978 + 367fce9 commit fe01193
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 52 deletions.
12 changes: 7 additions & 5 deletions AQGridView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 45;
objectVersion = 46;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -212,8 +212,11 @@
/* Begin PBXProject section */
0867D690FE84028FC02AAC07 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0420;
};
buildConfigurationList = 1DEB922208733DC00010E9CD /* Build configuration list for PBXProject "AQGridView" */;
compatibilityVersion = "Xcode 3.1";
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 1;
knownRegions = (
Expand Down Expand Up @@ -285,7 +288,6 @@
COPY_PHASE_STRIP = NO;
DSTROOT = /tmp/AQGridView.dst;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
Expand All @@ -295,6 +297,7 @@
INSTALL_PATH = /usr/local/lib;
IPHONEOS_DEPLOYMENT_TARGET = 4.0;
PRODUCT_NAME = AQGridView;
SKIP_INSTALL = YES;
};
name = Debug;
};
Expand All @@ -313,6 +316,7 @@
INSTALL_PATH = /usr/local/lib;
IPHONEOS_DEPLOYMENT_TARGET = 4.0;
PRODUCT_NAME = AQGridView;
SKIP_INSTALL = YES;
};
name = Release;
};
Expand All @@ -326,7 +330,6 @@
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 3.0;
OTHER_LDFLAGS = "-ObjC";
PREBINDING = NO;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand All @@ -341,7 +344,6 @@
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 3.0;
OTHER_LDFLAGS = "-ObjC";
PREBINDING = NO;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand Down
10 changes: 5 additions & 5 deletions Classes/AQGridView.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ extern NSString * const AQGridViewSelectionDidChangeNotification;
NSIndexSet * _animatingIndices;

NSMutableIndexSet * _highlightedIndices;
UIView * _touchedContentView; // weak reference
UIView * __unsafe_unretained _touchedContentView; // weak reference

UIView * _backgroundView;
UIColor * _separatorColor;
Expand Down Expand Up @@ -151,10 +151,10 @@ extern NSString * const AQGridViewSelectionDidChangeNotification;

unsigned delegateWillDisplayCell:1;
unsigned delegateWillSelectItem:1;
unsigned delegateWillSelectItemMultiTouch:1;
unsigned delegateWillSelectItemMultiTouch:1;
unsigned delegateWillDeselectItem:1;
unsigned delegateDidSelectItem:1;
unsigned delegateDidSelectItemMultiTouch:1;
unsigned delegateDidSelectItemMultiTouch:1;
unsigned delegateDidDeselectItem:1;
unsigned delegateGestureRecognizerActivated:1;
unsigned delegateAdjustGridCellFrame:1;
Expand All @@ -168,8 +168,8 @@ extern NSString * const AQGridViewSelectionDidChangeNotification;
} _flags;
}

@property (nonatomic, assign) IBOutlet id<AQGridViewDataSource> dataSource;
@property (nonatomic, assign) IBOutlet id<AQGridViewDelegate> delegate;
@property (nonatomic, unsafe_unretained) IBOutlet id<AQGridViewDataSource> dataSource;
@property (nonatomic, unsafe_unretained) IBOutlet id<AQGridViewDelegate> delegate;

@property (nonatomic, assign) AQGridViewLayoutDirection layoutDirection;

Expand Down
67 changes: 27 additions & 40 deletions Classes/AQGridView.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ - (void) deleteVisibleCell: (AQGridViewCell *) cell atIndex: (NSUInteger) visibl

@interface AQGridView ()
@property (nonatomic, copy) NSIndexSet * animatingIndices;
- (void) cellUpdateAnimationStopped: (NSString *) animationID finished: (BOOL) finished context: (void *) context;
@end


Expand Down Expand Up @@ -908,8 +907,8 @@ - (void) setupUpdateAnimations
- (void) endUpdateAnimations
{
NSAssert([_updateInfoStack lastObject] != nil, @"_updateInfoStack should not be empty at this point" );

AQGridViewUpdateInfo * info = [_updateInfoStack lastObject];
__block AQGridViewUpdateInfo * info = [_updateInfoStack lastObject];

if ( info.numberOfUpdates == 0 )
{
Expand All @@ -931,46 +930,34 @@ - (void) endUpdateAnimations
[NSException raise: NSInternalInconsistencyException format: @"Invalid number of items in AQGridView: Started with %u, added %u, deleted %u. Expected %u items after changes, but got %u", (unsigned)_gridData.numberOfItems, (unsigned)numAdded, (unsigned)numDeleted, (unsigned)expectedItemCount, (unsigned)actualItemCount];
}

// there's a race condition with the info's removal from the stack if there are no animations taking place,
// where -cellUpdateAnimationStopped:finished:context: is called immediately, before we've finished with the
// object. Therefore we retain it while we want to use it, just in case

[info cleanupUpdateItems];
_animationCount++;
//NSAssert(_animationCount == 1, @"Stacked animations occurring!!");

[UIView beginAnimations: @"CellUpdates" context: (void*)objc_unretainedPointer(info)];
[UIView setAnimationDelegate: self];
[UIView setAnimationDidStopSelector: @selector(cellUpdateAnimationStopped:finished:context:)];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration: 0.3];

self.animatingCells = [info animateCellUpdatesUsingVisibleContentRect: [self gridViewVisibleBounds]];


_gridData = [info newGridViewData];
if ( _selectedIndex != NSNotFound )
_selectedIndex = [info newIndexForOldIndex: _selectedIndex];

_reloadingSuspendedCount--;
[UIView commitAnimations];
}

- (void) cellUpdateAnimationStopped: (NSString *) animationID finished: (BOOL) finished context: (void *) context
{
AQGridViewUpdateInfo * info = (__bridge AQGridViewUpdateInfo *)context;

// if nothing was animated, we don't have to do anything at all
// if ( self.animatingCells.count != 0 )
[self fixCellsFromAnimation];

// NB: info becomes invalid at this point
[_updateInfoStack removeObject: info];
_animationCount--;

//_reloadingSuspendedCount--;
if ( _flags.delegateDidEndUpdateAnimation == 1 )
[self.delegate gridViewDidEndUpdateAnimation: self];

[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseInOut
animations:^(void) {
self.animatingCells = [info animateCellUpdatesUsingVisibleContentRect: [self gridViewVisibleBounds]];


_gridData = [info newGridViewData];
if ( _selectedIndex != NSNotFound )
_selectedIndex = [info newIndexForOldIndex: _selectedIndex];

_reloadingSuspendedCount--;
}
completion:^(BOOL finished) {
// if nothing was animated, we don't have to do anything at all
// if ( self.animatingCells.count != 0 )
[self fixCellsFromAnimation];

// NB: info becomes invalid at this point
[_updateInfoStack removeObject: info];
_animationCount--;

//_reloadingSuspendedCount--;
if ( _flags.delegateDidEndUpdateAnimation == 1 )
[self.delegate gridViewDidEndUpdateAnimation: self];
}];
}

- (void) beginUpdates
Expand Down
2 changes: 1 addition & 1 deletion Classes/AQGridViewData.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

@interface AQGridViewData : NSObject <NSCopying, NSMutableCopying>
{
AQGridView * _gridView; // weak reference
AQGridView * __unsafe_unretained _gridView; // weak reference
CGSize _boundsSize;
AQGridViewLayoutDirection _layoutDirection;
CGSize _desiredCellSize; // NB: 'cell' here means a grid cell -- i.e. constant size, tessellating
Expand Down
2 changes: 1 addition & 1 deletion Classes/AQGridViewUpdateInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
NSMutableIndexSet * _onlyMovedIndices;

// needs to ask the grid view for cells
AQGridView * _gridView; // weak reference
AQGridView * __unsafe_unretained _gridView; // weak reference

NSMutableSet * _animatingCells;
}
Expand Down

0 comments on commit fe01193

Please sign in to comment.