Tag: 自动ref counting

为什么Xcode为IBOutlet创build一个弱引用?

我注意到,当我在故事板内创build一个sockets,它会生成以下代码__weak IBOutlet UILabel *mLabel; 。 为什么它宣称它是一个弱指针? 据我了解,当对象被释放时,其所有成员也将被释放。 在我的大部分代码中,我宣称这些网点是强大的指针。 这会造成问题吗?

使用ARC对CGMutablePathRef进行编码和解码

在ARC下,是否可以使用NSCoding对CGMutablePathRef (或其不可变forms)进行编码/解码? 天真地我尝试: path = CGPathCreateMutable(); … [aCoder encodeObject:path] 但是我从编译器中得到一个友好的错误: Automatic Reference Counting Issue: Implicit conversion of an Objective-C pointer to 'CGMutablePathRef' (aka 'struct CGPath *') is disallowed with ARC 我能做些什么来编码?

ios5从mapview中删除注释

我刚刚开始在iOS,有一个初学者的问题。 我只是想添加并从我的地图删除一个别针,但得到一个错误: MapViewAnnotation类的实例0x6ec5750被释放,而键值观察者仍然在其中注册。 观测信息被泄露,甚至可能被误认为是其他物体。 我有一个带有头文件的MapViewAnnotation类 #import <Foundation/Foundation.h> #import <MapKit/MapKit.h> @interface MapViewAnnotation : NSObject <MKAnnotation>{ NSString *title; CLLocationCoordinate2D coordinate; } @property (nonatomic, copy) NSString *title; @property (nonatomic, readonly) CLLocationCoordinate2D coordinate; – (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d; @end 和#import“MapViewAnnotation.h”的.m文件 @implementation MapViewAnnotation @synthesize title, coordinate; – (id)initWithTitle:(NSString *)ttl andCoordinate:(CLLocationCoordinate2D)c2d { self = [super init]; title = ttl; coordinate = c2d; […]

使用块和ARC导致“消息发送到解除分配的实例”错误

我遇到了ARC和块的问题,但解决了这个问题。 不幸的是,我不知道究竟发生了什么,想了解更多的情况。 原来,我有这样做的代码 for(__block id<Foo> object in objects) { foo download:someParm success:^{ object.state = StateNewState; } ]; } 这导致了保留的不平衡。 一个对象被访问时发生崩溃,并且被认为已经被释放。 我写了一个实现并使用“copy”属性的类来创build一个successBlock属性,该属性保存了传递给下载函数成功参数的块。 我用下面的代码replace了这个代码 for(id<Foo> object in objects) { foo download:someParm success:^(id<Foo> successObject){ successObject.state = StateNewState; } ]; } 没有更多的释放对象错误,但我还没有运行仪器来检查是否没有泄漏。 有些如何使用__block导致对象被释放太多次,我不明白为什么。 我会继续研究这个问题的原因,但是我认为这对其他人来说是一个有趣的问题。 我想可能值得注意的是objects数组是一个autoreleased数组,它是在我之前在这篇文章中写下的代码行中创build的。 不要以为这会很重要,但我认为我只是通过那里。 我放在这篇文章中的代码并不是确切的代码,因为我正在使用这个工作,并且里面有一堆绒毛。 但是for循环中没有创build其他对象。 当应用程序崩溃,它运行下载,然后运行callback,顺便说一句,我使用ASIHttp。 当我试图再次下载它运行和callback不会被调用,因为对象已被释放,委托没有。 之后,当对象被包含指向对象的指针的字典访问时,我们会崩溃。

Xcode应用程序不释放内存

我正在创build一个应用程序,在设备中存储图像(保存为coreData),我有一个问题。 每次我select一个图片添加collectionView时,内存都在100Mb左右增加,而且每增加一次。 我想我加了ARC,(Edit-> refactor-> convert to objective-c ARC ..),添加它似乎没有任何问题,但内存仍然不释放。 这是我的代码,当用户在uiimagepicker中select图像时: – (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *chosenImage = info[UIImagePickerControllerOriginalImage]; NSData *imageData = UIImageJPEGRepresentation(chosenImage ,0.2); if (imageData != nil) { AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate; NSString *urlString = [NSString stringWithFormat:@"myurl.."]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setURL:[NSURL URLWithString:urlString]]; [request setHTTPMethod:@"POST"]; NSString *boundry = […]

从JSON加载属性,得到“消息发送到解除分配的实例”

所以我加载我的自定义对象从Web服务,并试图存储属性作为NSStrings,但继续运行到这个错误: -[CFString _cfTypeID]: message sent to deallocated instance 0x100d3d40 -[CFString retain]: message sent to deallocated instance 0x100d3d40 我使僵尸,但这并不真正向我展示了一个解决scheme。 我的属性被定义为: @property (strong, nonatomic) NSString *title; @property (assign, nonatomic) NSString *ID; @property (strong, nonatomic) NSString *redLabel; @property (strong, nonatomic) NSString *greenLabel; 然后我创build我的对象的实例,并调用Web服务 QuickList *list = [[QuickList alloc] init]; [list loadLatestQuickList]; 最后,在loadLatestQuickList里面… NSURLRequest *request = // create a […]

通过使用自动引用计数问题隐式转换指针来获取错误

我得到一个错误一个Objective-C指针隐式转换为'无效'与ARC是不允许的 -(void)openAnimation { NSValue *contextPoint =[NSValue valueWithCGPoint:self.view.center]; [UIView beginAnimation:nil context:contextPoint]; // getting error here } 任何人都可以帮我解决这个错误 谢谢

使用ARC项目中的非ARC库的方法?

我使用的是非常棒的非ARC项目: https : //github.com/boredzo/iso-8601-date-formatter 我试图从这个在ARC项目中是非ARC的库中使用下面的方法: – (NSDate *) dateFromString:(NSString *)string timeZone:(out NSTimeZone **)outTimeZone; 我努力了: group.updatedAt = [formatter dateFromString:someString timeZone:[NSTimeZone localTimeZone]]; group.updatedAt = [formatter dateFromString:someString timeZone:*__autorelease [NSTimeZone localTimeZone]]; group.updatedAt = [formatter dateFromString:someString timeZone:(*__autoreleasing [NSTimeZone localTimeZone]] *); group.updatedAt = [formatter dateFromString:someString timeZone:[[NSTimeZone localTimeZone] autorelease]]; 请注意,我对iOS相当新,所以我没有任何内存pipe理的经验。 但是,所有这些尝试,我收到以下错误信息: Implicit conversion of an Objective-C pointer to 'NSTimeZone *__autoreleasing *' is […]

iPhone可到达的类

我已经添加了两个文件Reachability.h / m。 我遇到的问题是在ReachabilityCallback方法 NSCAssert([(NSObject*) info isKindOfClass: [Reachability class]], @"info was wrong class in ReachabilityCallback"); 错误消息是:将C指针types“void *”转换为Objective-C指针types“NSObject *”需要进行桥接转换 NSAutoreleasePool* myPool = [[NSAutoreleasePool alloc] init]; 错误:“NSAutoreleasePool”不可用:在自动引用计数模式下不可用 SCNetworkReachabilityContext context = {0, self, NULL, NULL, NULL}; 错误:ARC不允许将Object-C指针隐式转换为“void *” 有一堆ARC禁止“释放”/“自动释放”的显式消息发送。 是否有可用于ARC的代码版本? 谢谢

消息发送到ARC使用自定义getter和setter释放实例

我试图为我的自定义对象HFObject实现自定义getter和setter,并且尽pipe使用ARC,我的应用程序崩溃了Message sent to deallocated instance错误的Message sent to deallocated instance 。 我已经阅读了每一个相关的文章,那些在ARC之前编写的文章并不适用,其他一切都没有帮助。 我打开了僵尸对象debugging器选项。 设置自定义HObject 在HObject.h中我已经声明了这四个属性: @property (retain) NSString *email; //Will use custom getter/setter @property (retain) NSString *firstName; //Will use custom getter/setter @property (retain) NSDate *date; //Will use custom getter/setter @property (nonatomic, retain) NSMutableDictionary *values; 在实施HObject的时候,我删除了email的自动获取和设置。 firstName和date这样利用@dynamic @dynamic email; @dynamic firstName; @dynamic date; 我也在HObject init中分配values字典 – (id)init […]