retain

Retain/release of returned objects

只谈情不闲聊 提交于 2019-12-06 00:52:18
问题 I am new to Objective-C, so this might be a dumb question. I cannot help but see the similarities between ObjC and Microsoft's COM with respect to memory management ( AddRef / Release vs retain / release ). In a COM environment, it's more or less imposed on you to always AddRef ( retain ) an object before returning it to the caller. From what I've seen so far (I'm a third through Cocoa® Programming for Mac® OS X (3rd Edition)), the memory management part is somewhat fuzzy. Assuming there is

Does an NSManagedObject retain its NSManagedObjectContext?

旧街凉风 提交于 2019-12-05 16:58:23
NSManagedObject provides access to its NSManagedObjectContext , but does it retain it? According to "Passing Around a NSManagedObjectContext on iOS" by Marcus Zarra , "The NSManagedObject retains a reference to its NSManagedObjectContext internally and we can access it." How does Zarra know this and is he correct? I'm asking because I want to know if the NSManagedObjectContext will be dealloc 'ed in the tearDown method below. (I'm using CocoaPlant .) #import <SenTestingKit/SenTestingKit.h> #import <CocoaPlant/CocoaPlant.h> #import "AccountUser.h" @interface AccountUserTests : SenTestCase {

IBOutlet instances are (null) after loading from NIB

蓝咒 提交于 2019-12-05 12:51:56
问题 I am working on an iPhone app and am getting (null) references to IBOutlet fields in my controller. I have a UIViewController subclass that is set as the File's Owner in my XIB. I have a set of UI elements that are wired into the controller. After loading from NIB and attempting to set properties on those UI elements, I find that they are (null). To clarify, some code: ExpandSearchPageController.h: @interface ExpandSearchPageController : UIViewController { IBOutlet UITextView *

iOS 4 blocks and retain counts

房东的猫 提交于 2019-12-04 07:25:58
问题 I'm just getting started with blocks and Grand Central Dispatch. I've been told (and read in the Apple Documentation) that any object referenced from within a block gets retained. For instance: ^{ self.layer.transform = CATransform3DScale(CATransform3DMakeTranslation(0, 0, 0), 1, 1, 1); self.layer.opacity = 1; } "self" gets retained so it leaks. To avoid that, I need to assign self to: __block Object *blockSelf = self; and then use blockSelf instead of self inside my block. My question is:

Retain/release of returned objects

为君一笑 提交于 2019-12-04 06:25:41
I am new to Objective-C, so this might be a dumb question. I cannot help but see the similarities between ObjC and Microsoft's COM with respect to memory management ( AddRef / Release vs retain / release ). In a COM environment, it's more or less imposed on you to always AddRef ( retain ) an object before returning it to the caller. From what I've seen so far (I'm a third through Cocoa® Programming for Mac® OS X (3rd Edition) ), the memory management part is somewhat fuzzy. Assuming there is no GC, what is the idiomatic way to return an object? hamstergene Read Memory Management Programming

OK to retain ASIHTTPRequest delegate?

让人想犯罪 __ 提交于 2019-12-04 05:41:35
问题 Is it OK to retain a delegate of a subclass of ASIHTTPRequest ? I made a subclass of ASIHTTPRequest called JSONRequest . Each instance of JSONRequest is its own delegate, handles the callbacks, and passes them on to jsonDelegate , which is a private property of JSONRequest , and responds to requestFinished:withResult: , where result is an NSDictionary representation of the JSON response. To do this, I overloaded setDelegate: in JSONRequest to do super.delegate = self; self.jsonDelegate =

Is NSObject's retain method atomic?

孤街醉人 提交于 2019-12-04 01:48:27
Is NSObject's retain method atomic? For example, when retaining the same object from two different threads, is it promised that the retain count has gone up twice, or is it possible for the retain count to be incremented just once? Thanks. NSObject as well as object allocation and retain count functions are thread-safe — see Appendix A: Thread Safety Summary in the Thread Programming Guide . Edit : I’ve decided to take a look at the open source part of Core Foundation. In CFRuntime.c , __CFDoExternRefOperation() is the function responsible for updating the the retain counters. It tests whether

IBOutlet instances are (null) after loading from NIB

随声附和 提交于 2019-12-04 00:12:35
I am working on an iPhone app and am getting (null) references to IBOutlet fields in my controller. I have a UIViewController subclass that is set as the File's Owner in my XIB. I have a set of UI elements that are wired into the controller. After loading from NIB and attempting to set properties on those UI elements, I find that they are (null). To clarify, some code: ExpandSearchPageController.h: @interface ExpandSearchPageController : UIViewController { IBOutlet UITextView * completeMessageView; } -(void)checkTextField; @property (nonatomic, retain) IBOutlet UITextView * completeMessageView

NSZombies are eating my app's brain!

最后都变了- 提交于 2019-12-03 15:50:23
I've got a retain/release problem. My View is pretty complicated so I've set NSZombieEnabled to YES and am trying to locate which, exactly, object is causing me grief. To speed this process along I'm wondering if there hints or tricks to tracking the Zombies back to the grave they dug their way out of (sorry, had to) or, back to the object they're associated with? The cryptic console message doesn't appear to offer much insight: NSInvocation: warning: object 0x1076850 of class '_NSZombie_CALayer' does not implement methodSignatureForSelector: -- trouble ahead I have no selectors called

Memory Analyzer tool(MAT)分析内存泄漏

不想你离开。 提交于 2019-12-03 11:41:05
实例分析参考 http://www.blogjava.net/rosen/archive/2010/06/13/323522.html http://eclipsesource.com/blogs/2013/01/21/10-tips-for-using-the-eclipse-memory-analyzer/ 一、首先理解几个概念 Shallow Heap Size 指对象自身所占用的内存大小,不包含其引用的对象所占的内存大小。 1、数组类型 数组元素对象所占内存的大小总和。 2、非数组类型 对象与它所有的成员变量大小的总和。当然这里面还会包括一些java语言特性的数据存储单元。 Retained Heap Size 前对象大小+当前对象可直接或间接引用到的对象的大小总和。 (间接引用的含义:A->B->C, C就是间接引用) 换句话说,Retained Size就是当前对象被GC后,从Heap上总共能释放掉的内存。 不过,释放的时候还要排除被GC Roots直接或间接引用的对象。他们暂时不会被被当做Garbage。 GC Roots直接引用了A和B两个对象。 A对象的Retained Size=A对象的Shallow Size B对象的Retained Size=B对象的Shallow Size + C对象的Shallow Size 这里不包括D对象,因为D对象被GC