automatic-ref-counting

How to get the address of an objective c object into a void * volatile * under ARC?

ぐ巨炮叔叔 提交于 2020-01-04 04:04:07
问题 I have a simple objective c object NSManagedObjectContext * moc = nil Now I need to pass it into a function in an ARC environment that accepts parameter of type void *volatile * value I tried &((__bridge void *)moc)) but I get the following compiler error Address expression must be lvalue or a function pointer I also tried void ** addr = (__bridge void **)(&moc); But I get the error Incompatible types casting 'NSManagedObjectContext * __strong *' to 'void **' with a __bridge cast Is there any

Will multiple presentViewController method calls throughout the view controllers lead to memory leak in iOS?

断了今生、忘了曾经 提交于 2020-01-03 17:15:08
问题 I know there has been a lot of discussions occurred related to this topic. But in all discussions all have discussed with 2 view controllers (A&B). My scenario is similar but different. What will happen when there are multiple view controllers like A,B,C,D. So the presenting flow moves as , View controller A (Home) presents View controller B(List). Then from View controller B presents View Controller C (Details).Then from View Controller C presents View Controller D(Advanced Details). Then

Getting a error with implicit conversion of an pointer using Automatic reference Counting Issue

僤鯓⒐⒋嵵緔 提交于 2020-01-03 02:54:10
问题 I am getting an error Implicit conversion of an Objective-C pointer to 'void' is disallowed with ARC -(void)openAnimation { NSValue *contextPoint =[NSValue valueWithCGPoint:self.view.center]; [UIView beginAnimation:nil context:contextPoint]; // getting error here } Can anyone help me to solve this error Thank you 回答1: So first, I would point out that this type of thing is easier to do with the block based animation methods. For iOS4 and iOS5, Apple recommends that you use those newer methods

Core Data: Memory not released after manually faulting managed objects

孤人 提交于 2020-01-03 01:22:45
问题 I am using the following code to retrieve the maximum value of an attribute on Core Data - (NSDate*)latestDateForLocalEntity:(NSString*)entityString key:(NSString*)key inManagedObjectContext:(NSManagedObjectContext*)context { NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:entityString]; NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:key ascending:YES]; request.sortDescriptors = @[sortDescriptor]; NSError *localError; NSArray *localResults =

ARC and __unsafe_unretained

空扰寡人 提交于 2020-01-02 11:06:29
问题 I think I have a pretty good understanding of ARC and the proper use cases for selecting an appropriate lifetime qualifiers ( __strong , __weak , __unsafe_unretained , and __autoreleasing ). However, in my testing, I've found one example that doesn't make sense to me. As I understand it, both __weak and __unsafe_unretained do not add a retain count. Therefore, if there are no other __strong pointers to the object, it is instantly deallocated (with immutable strings being an exception to this

Using alloc, init in ARC enabled projects

删除回忆录丶 提交于 2020-01-02 03:28:19
问题 Actually I am working on a project with ARC enabled. I know using alloc and init is taking ownership of the object. I know, If I create a string like this NSString *myString = [[NSString alloc]initWithFormat:@"Something"]; then I need to release the myString on myself. What If I am using ARC enabled? I cannot release on myself. So will it create a leak? Or should I don't create object like this? I can create a string like below code too. NSString *myString = [NSString stringWithFormat:@

How in Swift to know that struct is deleted from Memory?

为君一笑 提交于 2020-01-02 01:18:06
问题 In swift class type has method deinit() in which we can define that instance of class will be removed from memory. How we can know for struct that it will be removed from memory? For example, struct Vehicle { ... } var v: Vehicle? = Vehicle() v = nil 回答1: A simple way is the using of a dummy class. Just create an empty class and implement there the deinit(). Then use this class in your struct as member, p.e. let dummyClass = DummyClass() Once the structure is released, the deinit() function

Private properties vs instance variables in ARC [duplicate]

眉间皱痕 提交于 2020-01-01 19:38:10
问题 This question already has an answer here : Best way of declaring private variables in cocoa (1 answer) Closed 6 years ago . Having ARC enabled for an iOS app, if I want a class to have a private value/object, it should be better to declare this: // .m file @interface MyClass () @property (strong, nonatomic) NSString *name; @end or this?: @implementation MyClass { NSString *name; } What memory management considerations should I have? Thanks! 回答1: You can use either approach. In the first case

objc_release EXC_BAD_ACCESS

蹲街弑〆低调 提交于 2020-01-01 19:16:49
问题 Unable to determine what is going on with this error. I am uploading a file in multiple segments. I have threaded my api calls into 7 concurrent threads. Here is the assembly code that it stops at. Here is my printed stack trace Finally the Stack window I do not have any DISPATCH_QUEUE_PRIORITY_LOW except for a #define for dispatch_get_low() and I do not have any calls to dispatch_get_low() as a little background, I am developing my app from xcode 4.4 and recently installed GM Seed 4.5 to

EXC_BAD_ACCES drawing shadow

非 Y 不嫁゛ 提交于 2020-01-01 15:32:11
问题 I am trying to add a shadow to my UIView, but in my drawRect method I get an EXC_BAD_ACCESS. (I am using ARC) -(void) drawRect:(CGRect)rect { CGColorRef lightColor = [UIColor colorWithRed:105.0f/255.0f green:179.0f/255.0f blue:216.0f/255.0f alpha:0.8].CGColor; CGColorRef shadowColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:0.4].CGColor; CGContextRef context = UIGraphicsGetCurrentContext(); // Draw shadow CGContextSaveGState(context); CGContextSetShadowWithColor(context, CGSizeMake