Tag: 自动ref counting

用于iOS ARC问题的BWDB SQLite包装

我正在尝试使用Bill Weinman的BWDB包装,可以在这里下载: http ://bw.org/iosdata/ 我不能把它转换成ARC,可以有更有经验的人看我吗? 主要问题是insertRow&updateRow方法中的va_list,idk如何处理它。 其余的错误很容易摆脱。 提前感谢任何帮助/build议! 头文件 // BWDB.h // Created by Bill Weinman on 2010-09-25. // Copyright 2010 The BearHeart Group, LLC. All rights reserved. #import <Foundation/Foundation.h> #import <sqlite3.h> #define defaultDatabaseFileName @"bwtest.db" #define BWDB_VERSION @"1.0.5" @interface BWDB : NSObject <NSFastEnumeration> { sqlite3 *database; sqlite3_stmt *statement; NSString *tableName; NSString *databaseFileName; NSFileManager *filemanager; // […]

NSString中的内存泄漏stringWithUTF8String:启用ARC

在我的应用程序中,我启用了ARC。 但是在我的应用程序中,下面的行根据仪器给我内存泄漏。 它在ios 7.0中。 -(id)init{ variables = [[NSMutableArray alloc] init]; // Leak events = [[NSMutableArray alloc] init]; //Leak return self; } 更新 但在我的应用程序,如果我做下面的东西,它不显示任何泄漏。 但我不能将项目添加到variables。 -(id)init{ variables = [[[NSMutableArray alloc] init] copy]; // No Leak events = [[[NSMutableArray alloc] init] copy]; //No Leak return self; } – NSString *utfString =[NSString stringWithUTF8String:(const char *)attr->children->content];//Leak – -(NSObject*)createObjectForClass:(NSString*)className{ Class […]

IOS,ARC,属性:(readwrite,nonatomic)vs(radwrite,retain,nonatomic)

我已经阅读了一些关于ARC的教程,在属性声明上仍然有点困惑。 我使用以下模式编写了大部分代码: @property (readwrite, nonatomic) PlayerData* playerData; @property (readwrite, nonatomic) MusicLayer* musicLayer; @property (readwrite, nonatomic) bool isPowerUpAvailable; 现在,我终于开始处理内存泄漏XCodebuild议我在一些代码中应该在属性声明中添加“retain”关键字。 使用ARC我以为我不应该“打扰”保留计数了。 有没有一些概念,我没有得到或失踪? 任何教程的参考或解释将不胜感激。

如何知道何时使`NSTimer`无效

这是我的问题: 我有一个模型类,其中有一个NSTimer ,我希望计时器运行模型对象的整个生命周期。 初始化很简单:我只是在init方法中有以下代码行: self.maintainConnectionTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(maintainConnection) userInfo:nil repeats:YES]; 但是,我的问题是, 当模型从内存中释放时 , 如何使这个计时器无效? 现在,这通常很容易,但是,据我所知,当您计划一个NSTimer ,操作系统维护一个强指针到Timer对象。 我该如何处理? 有没有一种方法在模型从内存中释放之前被调用?

在ARC应用程序中包含非ARC库?

那么,这可能吗? 我多次得到这个错误: ARC forbids Objective-C objects in structs or unions 例如这里: typedef struct { BOOL _field1; union { struct { id _field1; id _field2; } _field1; GSEventRef _field2; } _field2; } XXStruct_CKAdxD;

什么时候应该使用__bridge与CFBridgingRelease / CFBridgingRetain?

我有这个代码使用“__bridge”来投射颜色的ID: CGColorRef tabColor = (5 == 5 ? [UIColor blueColor].CGColor : [UIColor greenColor].CGColor); CGColorRef startColor = [UIColor whiteColor].CGColor; CGColorRef endColor = tabColor; NSArray *colors = [NSArray arrayWithObjects:(__bridge id)startColor, (__bridge id)endColor, nil]; CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)colors, locations); 但会: NSArray *colors = [NSArray arrayWithObjects:(id)CFBridgingRelease(startColor), (id)CFBridgingRelease(endColor), nil]; CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (CFArrayRef)CFBridgingRetain(colors), locations); 成为更好的解决scheme?

NSMakeCollectable和ARC不起作用

我正在尝试将我的旧项目转换为ARC。 我有一个创buildUUID的函数,但显然这在使用ARC时不再支持: NSString *uuid = nil; CFUUIDRef theUUID = CFUUIDCreate(kCFAllocatorDefault); if (theUUID) { uuid = NSMakeCollectable(CFUUIDCreateString(kCFAllocatorDefault, theUUID)); //[uuid autorelease]; CFRelease(theUUID); } 编译器错误(尝试转换时):'NSMakeCollectable'不可用:在自动引用计数模式下不可用。 所以我的问题是:如何在使用ARC时创buildUUID? 现在还有另外一种方法吗?

我的ARC应用程序如何在iOS 3.x中工作?

所以我刚刚发现ARC只支持运行iOS 4.0+的设备。 我的应用程序(在商店中)如何在运行iOS 3.0的设备上工作(绝对使用ARC)? 我很困惑。 从下面的解决scheme:只要我不使用零弱引用看起来,使用ARC仍然适用于iOS 3.x,但苹果只是不能保证结果。

iOS:如何在启用ARC的情况下从内存中删除对象?

我正在使用iOS 5 SDK开发iOS应用程序,启用了自动引用计数。 但是,我有一个特定的对象,正在大量创build,必须在一秒之后才能释放,否则设备将变得非常慢。 看起来他们没有被释放,因为设备非常慢。 有没有办法手动释放一个对象时启用ARC? 编辑:我的代码,这被称为每秒200次,以产生闪闪发光。 他们在0.8秒后淡出,所以他们在那之后是无用的。 int xanimationdiff = arc4random() % 30; int yanimationdiff = arc4random() % 30; if (arc4random()%2 == 0) { xanimationdiff = xanimationdiff * -1; } if (arc4random()%2 == 0) { yanimationdiff = yanimationdiff * -1; } Sparkle *newSparkle = [[Sparkle alloc] initWithFrame:CGRectMake(20 + arc4random() % 280, 20, 10, 10)]; […]

块获取释放,而在NSDictionary(ARC)

我试图保留一个Block的引用,这个Block被一个方法传递给我的类,稍后再调用。 我遇到了麻烦,但是保持对它的引用。 我认为,显而易见的方法是将其添加到伊娃集合中,所有这些都应该对其内容保持强有力的引用。 但是,当我试图把它拉回来,它是零。 代码非常简单: typedef void (^DataControllerCallback)(id rslt); @interface DataController : NSObject { NSMutableArray* queue; } – (void) addBlock:(DataControllerCallback)callback; – (void) functionToBeCalledLater; @end @implementation DataController – (id) init { self = [super init]; if (self != nil) { queue = [NSMutableArray new]; } return self; } – (void) addBlock:(DataControllerCallback)callback { NSDictionary* toAdd = [NSDictionary […]