Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix memory leaks and blocks' circular retentions

  • Loading branch information...
commit 62d2a9f25d30d3dadac0d69a0e92eab8517c382a 1 parent ae63370
Ernesto Rivera rivera-ernesto authored
38 examples/iOS/ColorObjectTracking/ColorObjectTracking/ColorTrackingViewController.m
View
@@ -69,12 +69,12 @@ - (void)configureVideoFiltering;
positionRawData = [[GPUImageRawDataOutput alloc] initWithImageSize:videoPixelSize resultsInBGRAFormat:YES];
__unsafe_unretained ColorTrackingViewController *weakSelf = self;
[positionRawData setNewFrameAvailableBlock:^{
- GLubyte *bytesForPositionData = positionRawData.rawBytesForImage;
- CGPoint currentTrackingLocation = [weakSelf centroidFromTexture:bytesForPositionData ofSize:[positionRawData maximumOutputSize]];
+ GLubyte *bytesForPositionData = weakSelf->positionRawData.rawBytesForImage;
+ CGPoint currentTrackingLocation = [weakSelf centroidFromTexture:bytesForPositionData ofSize:[weakSelf->positionRawData maximumOutputSize]];
// NSLog(@"Centroid from CPU: %f, %f", currentTrackingLocation.x, currentTrackingLocation.y);
CGSize currentViewSize = weakSelf.view.bounds.size;
dispatch_async(dispatch_get_main_queue(), ^{
- trackingDot.position = CGPointMake(currentTrackingLocation.x * currentViewSize.width, currentTrackingLocation.y * currentViewSize.height);
+ weakSelf->trackingDot.position = CGPointMake(currentTrackingLocation.x * currentViewSize.width, currentTrackingLocation.y * currentViewSize.height);
});
}];
@@ -86,38 +86,38 @@ - (void)configureVideoFiltering;
// NSLog(@"Average color: %f, %f, %f, %f", redComponent, greenComponent, blueComponent, alphaComponent);
CGSize currentViewSize = weakSelf.view.bounds.size;
dispatch_async(dispatch_get_main_queue(), ^{
- trackingDot.position = CGPointMake(currentTrackingLocation.x * currentViewSize.width, currentTrackingLocation.y * currentViewSize.height);
+ weakSelf->trackingDot.position = CGPointMake(currentTrackingLocation.x * currentViewSize.width, currentTrackingLocation.y * currentViewSize.height);
});
}];
videoRawData = [[GPUImageRawDataOutput alloc] initWithImageSize:videoPixelSize resultsInBGRAFormat:YES];
[videoRawData setNewFrameAvailableBlock:^{
- if (shouldReplaceThresholdColor)
+ if (weakSelf->shouldReplaceThresholdColor)
{
- CGSize currentViewSize = self.view.bounds.size;
- CGSize rawPixelsSize = [videoRawData maximumOutputSize];
+ CGSize currentViewSize = weakSelf.view.bounds.size;
+ CGSize rawPixelsSize = [weakSelf->videoRawData maximumOutputSize];
CGPoint scaledTouchPoint;
- scaledTouchPoint.x = (currentTouchPoint.x / currentViewSize.width) * rawPixelsSize.width;
- scaledTouchPoint.y = (currentTouchPoint.y / currentViewSize.height) * rawPixelsSize.height;
+ scaledTouchPoint.x = (weakSelf->currentTouchPoint.x / currentViewSize.width) * rawPixelsSize.width;
+ scaledTouchPoint.y = (weakSelf->currentTouchPoint.y / currentViewSize.height) * rawPixelsSize.height;
- GPUByteColorVector colorAtTouchPoint = [videoRawData colorAtLocation:scaledTouchPoint];
+ GPUByteColorVector colorAtTouchPoint = [weakSelf->videoRawData colorAtLocation:scaledTouchPoint];
- thresholdColor.one = (float)colorAtTouchPoint.red / 255.0;
- thresholdColor.two = (float)colorAtTouchPoint.green / 255.0;
- thresholdColor.three = (float)colorAtTouchPoint.blue / 255.0;
+ weakSelf->thresholdColor.one = (float)colorAtTouchPoint.red / 255.0;
+ weakSelf->thresholdColor.two = (float)colorAtTouchPoint.green / 255.0;
+ weakSelf->thresholdColor.three = (float)colorAtTouchPoint.blue / 255.0;
// NSLog(@"Color at touch point: %d, %d, %d, %d", colorAtTouchPoint.red, colorAtTouchPoint.green, colorAtTouchPoint.blue, colorAtTouchPoint.alpha);
- [[NSUserDefaults standardUserDefaults] setFloat:thresholdColor.one forKey:@"thresholdColorR"];
- [[NSUserDefaults standardUserDefaults] setFloat:thresholdColor.two forKey:@"thresholdColorG"];
- [[NSUserDefaults standardUserDefaults] setFloat:thresholdColor.three forKey:@"thresholdColorB"];
+ [[NSUserDefaults standardUserDefaults] setFloat:weakSelf->thresholdColor.one forKey:@"thresholdColorR"];
+ [[NSUserDefaults standardUserDefaults] setFloat:weakSelf->thresholdColor.two forKey:@"thresholdColorG"];
+ [[NSUserDefaults standardUserDefaults] setFloat:weakSelf->thresholdColor.three forKey:@"thresholdColorB"];
- [thresholdFilter setFloatVec3:thresholdColor forUniformName:@"inputColor"];
- [positionFilter setFloatVec3:thresholdColor forUniformName:@"inputColor"];
+ [weakSelf->thresholdFilter setFloatVec3:weakSelf->thresholdColor forUniformName:@"inputColor"];
+ [weakSelf->positionFilter setFloatVec3:weakSelf->thresholdColor forUniformName:@"inputColor"];
- shouldReplaceThresholdColor = NO;
+ weakSelf->shouldReplaceThresholdColor = NO;
}
}];
2  examples/iOS/CubeExample/Classes/DisplayViewController.m
View
@@ -27,7 +27,7 @@ - (void)dealloc
- (void)loadView
{
CGRect mainScreenFrame = [[UIScreen mainScreen] applicationFrame];
- GPUImageView *primaryView = [[GPUImageView alloc] initWithFrame:mainScreenFrame];
+ GPUImageView *primaryView = [[[GPUImageView alloc] initWithFrame:mainScreenFrame] autorelease];
self.view = primaryView;
renderer = [[ES2Renderer alloc] initWithSize:[primaryView sizeInPixels]];
7 examples/iOS/FeatureExtractionTest/FeatureExtractionTest/FeatureExtractionAppDelegate.m
View
@@ -170,6 +170,7 @@ - (void)testHoughTransform:(GPUImageHoughTransformLineDetector *)lineDetector of
[pictureInput removeAllTargets];
[pictureInput addTarget:lineDetector];
+ __unsafe_unretained GPUImageHoughTransformLineDetector * weakDetector = lineDetector;
[lineDetector setLinesDetectedBlock:^(GLfloat* lineArray, NSUInteger linesDetected, CMTime frameTime){
NSLog(@"Number of lines: %d", linesDetected);
@@ -191,7 +192,7 @@ - (void)testHoughTransform:(GPUImageHoughTransformLineDetector *)lineDetector of
dispatch_async(dispatch_get_main_queue(), ^{
NSUInteger currentImageIndex = 0;
- for (UIImage *currentImage in lineDetector.intermediateImages)
+ for (UIImage *currentImage in weakDetector.intermediateImages)
{
[self saveImage:currentImage fileName:[NSString stringWithFormat:@"%@-%@-%d.png", detectorName, pictureName, currentImageIndex]];
@@ -216,7 +217,7 @@ - (void)testCornerDetector:(GPUImageHarrisCornerDetectionFilter *)cornerDetector
[pictureInput addTarget:cornerDetector];
-
+ __unsafe_unretained GPUImageHarrisCornerDetectionFilter * weakDetector = cornerDetector;
[cornerDetector setCornersDetectedBlock:^(GLfloat* cornerArray, NSUInteger cornersDetected, CMTime frameTime) {
GPUImageCrosshairGenerator *crosshairGenerator = [[GPUImageCrosshairGenerator alloc] init];
crosshairGenerator.crosshairWidth = 10.0;
@@ -237,7 +238,7 @@ - (void)testCornerDetector:(GPUImageHarrisCornerDetectionFilter *)cornerDetector
dispatch_async(dispatch_get_main_queue(), ^{
NSUInteger currentImageIndex = 0;
- for (UIImage *currentImage in cornerDetector.intermediateImages)
+ for (UIImage *currentImage in weakDetector.intermediateImages)
{
[self saveImage:currentImage fileName:[NSString stringWithFormat:@"%@-%@-%d.png", detectorName, pictureName, currentImageIndex]];
8 examples/iOS/MultiViewFilterExample/MultiViewFilterExample/MultiViewViewController.m
View
@@ -20,7 +20,7 @@ - (void)didReceiveMemoryWarning
- (void)loadView
{
CGRect mainScreenFrame = [[UIScreen mainScreen] applicationFrame];
- UIView *primaryView = [[UIView alloc] initWithFrame:mainScreenFrame];
+ UIView *primaryView = [[[UIView alloc] initWithFrame:mainScreenFrame] autorelease];
primaryView.backgroundColor = [UIColor blueColor];
self.view = primaryView;
@@ -38,9 +38,9 @@ - (void)loadView
[self.view addSubview:view3];
[self.view addSubview:view4];
- GPUImageFilter *filter1 = [[GPUImageFilter alloc] initWithFragmentShaderFromFile:@"Shader1"];
- GPUImageFilter *filter2 = [[GPUImageFilter alloc] initWithFragmentShaderFromFile:@"Shader2"];
- GPUImageSepiaFilter *filter3 = [[GPUImageSepiaFilter alloc] init];
+ GPUImageFilter *filter1 = [[[GPUImageFilter alloc] initWithFragmentShaderFromFile:@"Shader1"] autorelease];
+ GPUImageFilter *filter2 = [[[GPUImageFilter alloc] initWithFragmentShaderFromFile:@"Shader2"] autorelease];
+ GPUImageSepiaFilter *filter3 = [[[GPUImageSepiaFilter alloc] init] autorelease];
// GPUImageBrightnessFilter *filter1 = [[GPUImageBrightnessFilter alloc] init];
// GPUImageBrightnessFilter *filter2 = [[GPUImageBrightnessFilter alloc] init];
5 examples/iOS/RawDataTest/RawDataTest/RawDataTestAppDelegate.m
View
@@ -30,9 +30,10 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[rawDataInput addTarget:customFilter];
[customFilter addTarget:rawDataOutput];
+ __unsafe_unretained GPUImageRawDataOutput * weakOutput = rawDataOutput;
[rawDataOutput setNewFrameAvailableBlock:^{
- GLubyte *outputBytes = [rawDataOutput rawBytesForImage];
- NSInteger bytesPerRow = [rawDataOutput bytesPerRowInOutput];
+ GLubyte *outputBytes = [weakOutput rawBytesForImage];
+ NSInteger bytesPerRow = [weakOutput bytesPerRowInOutput];
NSLog(@"Bytes per row: %d", bytesPerRow);
for (unsigned int yIndex = 0; yIndex < 10; yIndex++)
{
Please sign in to comment.
Something went wrong with that request. Please try again.