标签: automatic-ref-counting

是否有可能告诉ARC忽略一个对象?

最近将一个现有的iPhone项目转换为使用ARC,并且部分代码停止工作并且不断崩溃.似乎ARC正在自动发布myRequest:

ServerRequest *myRequest = [[ServerRequest alloc] init];
Run Code Online (Sandbox Code Playgroud)

在一些代表职能被解雇之前,太早了.

现在我从阅读ARC知道你可以设置-fno-objc-arc针对特定文件的编译器标志来忽略ARC.然而,现在工作正常,我仍然非常喜欢使用ARC.我想知道是否有人知道某种方式,当你实例化一个对象时,告诉ARC不要管理它的释放,例如:

ServerRequest *myRequest = [[[ServerRequest alloc] init] ignoreARC];
Run Code Online (Sandbox Code Playgroud)

xcode objective-c automatic-ref-counting

3
推荐指数
1
解决办法
727
查看次数

使用ARC编译时的ImageKit错误和警告

我正在尝试将我的项目转换为ARC,但我在我的项目中使用ImageKit.ARC重构工具和我自己的手动重构都会在ImageKit头文件中使用ARC生成错误和警告,这些文件已包含在我自己的源文件中.它们看起来像这样:

In file included from /Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Quartz.framework/Versions/A/Frameworks/ImageKit.framework/Headers/ImageKit.h:9:
In file included from /Volumes/Macintosh HD/Users/simone/Development/AFController.h:12:
In file included from /Volumes/Macintosh HD/Users/simone/Development/AFOperation.m:10:
/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Quartz.framework/Versions/A/Frameworks/ImageKit.framework/Headers/IKImageBrowserView.h:176:14: error: the current deployment target does not support automated __weak references [4]
     IBOutlet __weak NSScroller*                   _horizontalScroller;
              ^
<built-in>:115:31: note: instantiated from:
 #define __weak __attribute__((objc_ownership(weak)))
                               ^
In file included from /Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Quartz.framework/Versions/A/Frameworks/ImageKit.framework/Headers/ImageKit.h:9:
In file included from /Volumes/Macintosh HD/Users/simone/Development/AFController.h:12:
In file included from /Volumes/Macintosh HD/Users/simone/Development/AFOperation.m:10:
/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Quartz.framework/Versions/A/Frameworks/ImageKit.framework/Headers/IKImageBrowserView.h:177:14: error: the current deployment target does not support automated __weak references [4]
     IBOutlet __weak id                            _delegate;
              ^
<built-in>:115:31: …
Run Code Online (Sandbox Code Playgroud)

cocoa imagekit automatic-ref-counting

3
推荐指数
1
解决办法
1087
查看次数

获取ARC警告以强烈捕获ojbect

我正在使用ARC并收到警告说 Capturing 'request' strongly in this block is likely to a retain cycle.

__block ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:url];
[request setCompletionBlock:^{
        NSString *responseString = [request responseString];
        self.appointmentArray = [responseString JSONValue];
    }];
    [request setFailedBlock:^{
        NSError *error = [request error];
        NSLog(@"%@", error.description);
    }];
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch memory-management objective-c automatic-ref-counting

3
推荐指数
2
解决办法
2354
查看次数

这些对象何时在ARC下发布?

我有几个关于ARC(自动引用计数)的问题:

CFURLRef url = (__bridge CFURLRef)[NSURL fileURLWithPath:appPath];
//Question 1: Here, I would expect the NSURL object to be autoreleased and
//therefore the CFURLRef will also be available for “a while.” Is this correct?

url = NULL;
//Question 2: Will this cause the NSURL to be released immediately?
Run Code Online (Sandbox Code Playgroud)
NSURL *url = [NSURL fileURLWithPath:appPath];
url = nil;
//Question 3: Does the “url = nil” result in an immediate release of the NSURL?
Run Code Online (Sandbox Code Playgroud)
NSURL *url = [[NSURL alloc] initWithString:@"/something"];
url = nil;
//Question …
Run Code Online (Sandbox Code Playgroud)

cocoa cocoa-touch objective-c core-foundation automatic-ref-counting

3
推荐指数
1
解决办法
2144
查看次数

将非ARC文件子类化为Xcode 4中的ARC项目

我在ARC项目中使用了一些非ARC代码,即Three20.我添加了所有适当的编译器标志,一切正常.但是,我需要继承一些Three20类中的一些,并且我不确定是否应该将编译器标志添加到非ARC的新文件中,或者如果编译器将其解决,并添加适当的释放调用.

回顾一下: - XCode 4中的ARC项目 - 包括非ARC代码(Three20) - 需要子类化非ARC文件中定义的内容 - 我是否需要添加发布调用? - 我是否需要在子类中为非ARC添加编译器标志?

xcode objective-c three20 ios automatic-ref-counting

3
推荐指数
1
解决办法
1735
查看次数

EXC_BAD_ACCES绘制阴影

我想为我的UIView添加一个阴影,但在我的drawRect方法中,我得到一个EXC_BAD_ACCESS.(我正在使用ARC)

-(void) drawRect:(CGRect)rect {

    CGColorRef lightColor =  [UIColor colorWithRed:105.0f/255.0f green:179.0f/255.0f blue:216.0f/255.0f alpha:0.8].CGColor;

    CGColorRef shadowColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:0.4].CGColor;   

    CGContextRef context = UIGraphicsGetCurrentContext();
    // Draw shadow
    CGContextSaveGState(context);
    CGContextSetShadowWithColor(context, CGSizeMake(-5, 0), 10, shadowColor);
    CGContextSetFillColorWithColor(context, lightColor);
    CGContextFillRect(context, _coloredBoxRect);
    CGContextRestoreGState(context);
}
Run Code Online (Sandbox Code Playgroud)

错误消息: 线程1:编程接收信号:"EXC_BAD_ACCESS".

线: CGContextSetFillColorWithColor(context, lightColor);

当我将此行更改为:

[[UIColor colorWithRed:105.0f/255.0f green:179.0f/255.0f blue:216.0f/255.0f alpha:0.8] setFill];
Run Code Online (Sandbox Code Playgroud)

我得到了相同的错误,但在这一行:

CGContextSetShadowWithColor(context, CGSizeMake(-5, 0), 10, shadowColor);
Run Code Online (Sandbox Code Playgroud)

更新 我最终通过更改解决了问题:

CGColorRef shadowColor = [UIColor colorWithRed:0.2绿色:0.2蓝色:0.2 alpha:0.4] .CGColor;

至

float components [4] = {0,0,0,1.0/3.0}; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGColorRef shadowColor = CGColorCreate(colorSpace,components); …

core-graphics uiview cgcontext ios automatic-ref-counting

3
推荐指数
1
解决办法
1566
查看次数

ARC适用于所有对象?

在Book中,我找到了一个句子,告诉我ARC只发布了Foundation中的Object.这是真的?所以,如果我有:

MySimpleClass *objectFromMySimpleClass = [MySimpleClass alloc] init];
Run Code Online (Sandbox Code Playgroud)

我应该释放objectFromMySimpleClass?我怎样才能做到这一点?我试试的时候

[objectFromMySimpleClass release];
Run Code Online (Sandbox Code Playgroud)

我在Xcode提示中看到不活跃的"发布",然后编译器说我不能这样做,因为ARC.发生什么了?

等等.当我使用NSCoping协议时,我还应该在使用副本时释放对象?

memory-management objective-c ios automatic-ref-counting

3
推荐指数
1
解决办法
129
查看次数

内存泄漏iOS(UIImageView,UIImage,CGImage)未在ARC上释放

我试图实现一个简单的视频流但由于某种原因我的内存将不会被释放:

(void)updateImage:(UIImage *)image{
  self.indicator.hidden = TRUE;
  //CGImageRelease([self.imageView.image CGImage]);
  self.imageView.image = nil;
  self.imageView.image = image;
  [self.imageView setNeedsDisplay];
}
Run Code Online (Sandbox Code Playgroud)

如果我使用

CGImageRelease([self.imageView.image CGImage]);
Run Code Online (Sandbox Code Playgroud)

记忆将被释放.但是当我返回到以前的视图控制器时,应用程序将崩溃,因为它试图释放已经释放的图像的已分配内存.从异步任务调用此方法,该任务使用以下方法创建图像:

UIImage *image = [UIImage imageWithCGImage:cgImage];
CGImageRelease(cgImage);
CGDataProviderRelease(provider);
CFRelease(data);
Run Code Online (Sandbox Code Playgroud)

据我所知,UIImage现在拥有CGImage,我不应该释放它.因此,当我用新图像更新UIImageView时,是否确保释放UIImage?

memory-leaks uiimageview uiimage ios automatic-ref-counting

3
推荐指数
1
解决办法
4680
查看次数

Cocos2d 2.0:何时是"清除"缓存的好习惯?

在每个场景的开头调用以下"清除"方法是一种好习惯吗?如果不是,我应该什么时候打电话给他们,是否有任何教程解释何时使用每个电话?我错过了什么吗?

    [CCTextureCache purgeSharedTextureCache];
    [CCSpriteFrameCache purgeSharedSpriteFrameCache];
    [CCAnimationCache purgeSharedAnimationCache];
    [CCShaderCache purgeSharedShaderCache];
    [[CCFileUtils sharedFileUtils] purgeCachedEntries];
Run Code Online (Sandbox Code Playgroud)

(我正在使用Cocos2d 2.0并启用了ARC,不要认为它是相关的,但仍然认为值得一提)

memory-management cocos2d-iphone ios automatic-ref-counting cctexturecache

3
推荐指数
1
解决办法
1061
查看次数

ios - 'autorelease is unavailable'错误和'ARC禁止显式消息发送autorelease'错误

我有一个工作正常的应用程序.然后我尝试将导航控制器嵌入到tabbarcontroller中,接下来我知道我在编译期间开始收到这些错误.

谁会知道为什么这些会发生?某些设置是否未经检查或意外检查?

谢谢,亚历克斯

reference-counting ios automatic-ref-counting ios6

3
推荐指数
1
解决办法
1万
查看次数