automatic-ref-counting

Setting uiimage to nil doesn't release memory with ARC

守給你的承諾、 提交于 2019-11-30 22:46:37
I have a scrollview that shows different images as it's scrolled through the pages, like PhotoScroller. I'm using ARC. When someone scrolls to another page, I set the image property of the UIImageView not being currently show to nil, as (attempting) to avoid memory crashes, which are still happening. Then when the user scrolls to a new page, the image for that page is set as the UIImageView's image property, as well as the page before and after it (for smooth viewing). The UIImage's for the pages are all held in an array. Yet as I scroll through the pages, memory usage keeps going up, as if

Which is the cause for dyld`dyld_fatal_error, a incompatible api on iOS?

拟墨画扇 提交于 2019-11-30 22:44:01
问题 I'm moving part of my projects to iOS 5 / ARC. One of the oldest project (iOS 4.2, armv6 for support iPod Touch 2g) is giving to me: dyld`dyld_fatal_error: 0x8feb1070: int3 0x8feb1071: nop Just after the launch image but before going to main. Must be some lib/code updated to iOS 5, but which one? Is possible to use a better method than guess?? 回答1: Ran to this problem myself trying to reproduce this project using Xcode4.3.2 with SDK iOS5.1. The issue was that the standard project template on

Why does NSObject's “isMemberOfClass:class” specify __unsafe_unretained in XCode's autocompletion?

丶灬走出姿态 提交于 2019-11-30 22:38:54
The vague overview is that I'm writing a method in an NSArray Category that will take a Class and filter an Array down to elements that are members of that class. Something like: @implementation NSArray(filter) -(NSArray*)objectsOfClass:(Class)aClass { NSMutableArray *ret = [[NSMutableArray alloc] init]; for (id obj in self) if ([obj isMemberOfClass:aClass]) [ret addObject:obj]; return [NSArray arrayWithArray:ret]; } @end Sooo, with that out of the way, on to my question. NSObject.h shows that isMemberOfClass: has the following signature: -(BOOL)isMemberOfClass:(Class)aClass; When I type this

Keep object alive until a background task finishes

陌路散爱 提交于 2019-11-30 22:34:39
I am trying to implement a method that executes a task in the background and then calls a block on the main thread: + (void)migrateStoreWithCompletionHandler:(MigrationControllerCompletion)completion { MigrationController *controller = [[MigrationController alloc] initWithCompletionBlock:completion]; [controller migrateStore]; } This is the -initWithCompletionBlock: method: - (id)initWithCompletionBlock:(MigrationControllerCompletion)completion { self = [super init]; if (self) { _completion = [completion copy]; } return self; } The background work happens in -migrateStore . The problem is that

App Crashes saying Memory Warning Using Arc [closed]

删除回忆录丶 提交于 2019-11-30 22:32:11
I am using ARC and the app crashes saying received memory warning . I have used the apple instruments: It looks like I do not have any leaks but I cannot find where is wrong. The crash has to do with the memory and due arc I cannot use release and any sort. It is my first time dealing with memory usage using arc. Is there away I can Debug this since I am dealing this for nearly two months. I have my code on my git hub so it will be helpful if you look at it. You can find it here. I am dealing this problem for weeks and want to end this. Thanks. Not all "leaks" show up in the "Leaks" tool in

Avoiding circular retention using ARC (strong/weak), learning some basics

大兔子大兔子 提交于 2019-11-30 22:09:22
I haven't seemed to run into a problem yet, but I'm trying to make sure I'm using some best practices. Say I have a UITableViewController with a data source of an NSArray of MyObject objects. So in my UITableViewController I declare my data source like: @property (strong, nonatomic) NSArray *dataSource; Then after I touch a cell I want to push a new view that shows a detail view of something, using that cell's MyObject. So in the new UIViewController I have this: @property (strong, nonatomic) MyObject *myObject; Now in the UITableViewController when a cell is touched: MyObject *myObject = [

How can a weakly retained block cause a retain cycle when capturing “self”

天涯浪子 提交于 2019-11-30 20:24:06
问题 I have a class with a property which is a weak reference to a block. @interface BlockTest : NSObject @property (nonatomic, weak) void(^testBlock)(); @end At another point in the class I use this block like this: - (void)foobar { self.testBlock = ^{ [self doSomething]; }; } The compiler (Apple LLVM 3.0) complains that there might be a retain cycle because self is strongly captured here. But I fail to see how this leads to a retain cycle because the block itself is a __weak reference, so it

Capturing a variable in a Block when the Block is in the initializer

半腔热情 提交于 2019-11-30 20:22:18
Consider this: id observer = [[NSNotificationCenter defaultCenter] addObserverForName:MyNotification object:nil queue:nil usingBlock:^(NSNotification *note) { [[NSNotificationCenter defaultCenter] removeObserver:observer name:MyNotification object:nil ]; // do other stuff here... } ]; I'm using this pattern to observe a notification once and then stop observing it. But LLVM tells me (under ARC) that Variable 'observer' is uninitialized when captured by block. How can I fix this, since the block necessarily captures the variable before initialization, it being part of the initializer? Will

Using unowned inside of a capture list causing a crash even the block itself isn't executed

社会主义新天地 提交于 2019-11-30 20:04:09
Here, I was playing with leaks, so I've made a strong reference cycle intentionally to see if the Instruments will detect something, and I got unexpected results. The leak shown in Instruments certainly make sense, but the random crash is a bit mysterious (due to two facts I will mention later). What I have here is a class called SomeClass : class SomeClass{ //As you can guess, I will use this shady property to make a strong cycle :) var closure:(()->())? init(){} func method(){} deinit {print("SomeClass deinited")} } Also I have two scenes, the GameScene : class GameScene: SKScene { override

Keep object alive until a background task finishes

跟風遠走 提交于 2019-11-30 18:01:09
问题 I am trying to implement a method that executes a task in the background and then calls a block on the main thread: + (void)migrateStoreWithCompletionHandler:(MigrationControllerCompletion)completion { MigrationController *controller = [[MigrationController alloc] initWithCompletionBlock:completion]; [controller migrateStore]; } This is the -initWithCompletionBlock: method: - (id)initWithCompletionBlock:(MigrationControllerCompletion)completion { self = [super init]; if (self) { _completion =