小编use*_*816的帖子

iPhone CGRectMake内存消耗

在iPhone上..为什么这样的代码会导致内存泄漏?2分钟后,净字节数翻了一番.我正在做的就是用NSTimer调用以下方法在屏幕上移动一个球.

有任何想法吗?

- (void)nextFrame:(NSNotification *)notification {
    ballInstance.frame = CGRectMake(value, 0,  320, 480);
}
Run Code Online (Sandbox Code Playgroud)

这里是'完整'代码,新项目,仍然表现相同.它会在屏幕上移动jpg,因为它会大量消耗内存.如果我从'value'中删除'++',那么内存就没问题了.(换句话说有一个静态图形)所以....是缓存的图像是问题吗?如果是这样,我怎么能阻止它达到天文尺寸?

- (void)applicationDidFinishLaunching:(UIApplication *)application {    


    [window makeKeyAndVisible];

    NSTimer * nSTimer =[NSTimer scheduledTimerWithTimeInterval: .02
         target: self
       selector: @selector(tick)
       userInfo: nil
        repeats: YES];
    value =0;
}

- (void)tick {
    NSLog(@"tick");
    myOutlet1.frame = CGRectMake(value++, 0,  320, 480);
}
Run Code Online (Sandbox Code Playgroud)

iphone cocoa memory-leaks objective-c

2
推荐指数
1
解决办法
2249
查看次数

未调用NSEntityMigrationPolicy子类方法

我正在尝试从一个.xcdatamodel文件迁移到另一个。我有一个NSEntityMigrationPolicy子类,其名称已在xcode-> .xcmappingmodel文件->实体->“自定义策略”字段中输入。

我运行我的应用程序,该应用程序成功打开并运行了我的数据的先前版本,因此我只能假定基本迁移已奏效。但是我的NSEntityMigrationPolicy子类方法没有被调用,所以我可以运行更多的迁移代码。

@implementation TestMigrationPolicy

- (BOOL)beginEntityMapping:(NSEntityMapping *)mapping manager:(NSMigrationManager *)manager error:(NSError * *)error
{
    NSLog(@"this log is never shown!!!!");
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

有谁知道为什么我的它可能不会被调用?我是核心数据迁移的新手,但现在我茫然不知为什么这种行为不符合我的预期。

如果有帮助,我将像这样创建持久性存储。

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                         [NSNumber numberWithBool:YES], 
                         NSMigratePersistentStoresAutomaticallyOption,
                         [NSNumber numberWithBool:YES],
                         NSInferMappingModelAutomaticallyOption,
                         nil];


NSError *error = nil;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
NSLog(@"storeUrl  %@", storeUrl);

if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) {
Run Code Online (Sandbox Code Playgroud)

iphone cocoa core-data objective-c

2
推荐指数
1
解决办法
1937
查看次数

标签 统计

cocoa ×2

iphone ×2

objective-c ×2

core-data ×1

memory-leaks ×1