automatic-ref-counting

How does the ARC's zeroing weak pointer behavior implemented?

可紊 提交于 2019-11-30 06:53:46
I'm studying ARC. And now about zeroing weak pointer. OK I understood all the features. The semantic of weak reference is just same with weak reference of GC system, but you know, Objective-C doesn't use GC (except special case) so I can't understand how this works. I'm a little complicated guy, so I need to know underlying implementation principal to accept the feature to use. But the problem is it's very hard to find document which describes the principal of zeroing-weak pointer :( IMO, the only way to make this work is tracking and keeping all pointers referencing itself at runtime, and

Blocks inside NSMutableArray leaking (ARC)

佐手、 提交于 2019-11-30 05:37:42
问题 I have some operations that are inside blocks. This operations, only update an UIImage like this: ^(UIImage *image) { self.myImage = image; }]; My image is calculated by accessing the internet with a NSURLConnection . When I receive the image from the internet, I call that block that is inside a NSMutableArray . So far so good. My issue is that when I have multiple images that have the same URL, instead of making multiple calls, I just add a new block to the NSMutableArray inside the class

Does IBOutlet imply __weak?

懵懂的女人 提交于 2019-11-30 05:25:07
Just starting out with ARC. Pre-ARC, I would just simply declare my outlets as for example: IBOutlet UIButton *button; so I am not retaining it or anything. With ARC, not specifying weak or strong implies strong. So if I do the same thing under ARC (i.e. IBOutlet UIButton *button; ), does this mean button is a strong reference? or Do I have to explcility define it as weak? In short, does IBOutlet imply __weak? The word IBOutlet is actually defined as nothing: #define IBOutlet Xcode just uses the presence of this word in your code for purposes of allowing you to make connections in Interface

With ARC why use @properties anymore?

女生的网名这么多〃 提交于 2019-11-30 05:17:17
In non-ARC code retained properties handily take care of memory management for you using the self.property = syntax, so we were taught to use them for practically everything. But now with ARC this memory management is no longer an issue, so does the reason for using properties evaporate? is there still any good reason (obviously other than providing public access to instance variables) to use properties anymore? But now with ARC this memory management is no longer an issue, so does the reason for using properties evaporate? is there still any good reason (obviously other than providing public

Using objc_getClassList under arc

随声附和 提交于 2019-11-30 04:51:50
Has anybody managed to use objc_getClassList under arc, short of turning arc off for the file in question? The fundamental problem is that one of the parameters is a C array of Class pointers. This code should work under ARC: int numClasses; Class *classes = NULL; classes = NULL; numClasses = objc_getClassList(NULL, 0); NSLog(@"Number of classes: %d", numClasses); if (numClasses > 0 ) { classes = (__unsafe_unretained Class *)malloc(sizeof(Class) * numClasses); numClasses = objc_getClassList(classes, numClasses); for (int i = 0; i < numClasses; i++) { NSLog(@"Class name: %s", class_getName

Weak object in an NSDictionary?

こ雲淡風輕ζ 提交于 2019-11-30 04:47:26
I would like to store a zeroing weak reference to an object in a NSDictionary . This is for a reference to a parent NSDictionary , so I can crawl back up a large structure without searching. I can not use __weak here; even if my local reference is weak, the NSDictionary will store a strong reference to the object that was weakly referenced. And, of course, NSDictionary can't have nil objects. I'm on iOS, not Mac, so NSHashTable isn't available. And I only want one object to be weak; the rest should still be strong. (I'm going to post my answer, so I have something to mark as accepted if there

ARC circular retain detection

痞子三分冷 提交于 2019-11-30 04:09:57
I ported some old code over to Objective-C ARC (Automatic Reference Counting) and it seems to work great. Except a rather large, high-level object is not being deallocated when it is popped off of my navigation stack, making me believe I have a retain cycle somewhere that ARC has hidden from me (or at least made difficult to track down). What is the best way to weed out this potential retain cycle and/or what is a good way to determine the cause of a memory leak under ARC? Thanks! The best way is usually to use the Leaks instrument in the Instruments app . The What's New In Instruments video

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

非 Y 不嫁゛ 提交于 2019-11-30 03:59:50
问题 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

Memory warning and crash (ARC) - how to identify why it's happening?

心已入冬 提交于 2019-11-30 03:29:43
I've started to use the ARC recently and since then I blame it for every single memory problem. :) Perhaps, you could help me better understand what I'm doing wrong. My current project is about CoreGraphics a lot - charts drawing, views filled with thumbnails and so on. I believe there would be no problem while using manual memory management, except maybe a few zombies... But as of now, application simply crashes every time I try to either create a lot of thumbnails or redraw a bit more complicated chart. While profiling with Instruments I can see an awfully high value in resident memory as

Is it possible to see the code generated by ARC at compile time?

百般思念 提交于 2019-11-30 02:36:11
I have read the Transitioning to ARC Release Notes in "Summary" Section. They told : ARC works by adding code at compile time to ensure that objects live as long as necessary, but no longer. Conceptually, it follows the same memory management conventions as manual reference counting (described in Advanced Memory Management Programming Guide) by adding the appropriate memory management calls for you. In order for the compiler to generate correct code I wonder what result that ARC corrected our code. My question : Can we see the change? (In the term of alloc , retain , assign or release .Not