automatic-ref-counting

How to keep a variable in memory until the app quits

北城以北 提交于 2019-12-21 20:44:25
问题 I have a singleton object in iOS that when instantiated parses a CSV file and then holds the results. I would like to make this object universally accessible and I would like it to not be released from memory until the app quits. I am running ARC so I cannot do manual retains. Is there a way I can do this so it will work with ARC? Header File: #import <Foundation/Foundation.h> #import "CHCSV.h" #import "RCParserObject.h" @interface ParserStore : NSObject <CHCSVParserDelegate> { // CSV

When do these objects get released under ARC?

南笙酒味 提交于 2019-12-21 20:18:36
问题 I have a few questions about ARC (automatic reference counting): CFURLRef url = (__bridge CFURLRef)[NSURL fileURLWithPath:appPath]; //Question 1: Here, I would expect the NSURL object to be autoreleased and //therefore the CFURLRef will also be available for “a while.” Is this correct? url = NULL; //Question 2: Will this cause the NSURL to be released immediately? NSURL *url = [NSURL fileURLWithPath:appPath]; url = nil; //Question 3: Does the “url = nil” result in an immediate release of the

Guarantees about the lifetime of a reference in a local variable

跟風遠走 提交于 2019-12-21 19:54:20
问题 In Swift , I can use the ARC mechanism to manage the lifetime of resources external to the process because instances of classes are de-initialized predictably. This is in contrast to environments like the Java Runtime where instances are de-initialized when the garbage collector collects the object, which is not guaranteed to happen in a defined time window. But what are the exact guarantees that the Swift language and runtime make about the lifetime of instances when those instances are

How to release a Firemonkey control properly, in this case a child form with a parent?

自闭症网瘾萝莉.ら 提交于 2019-12-21 19:42:31
问题 From inside an event handler of the control itself, I would like to delete and free it. A typical use case for TFmxObject.Release , isn't it? However, it only seems to work under Windows, but not Android, and this method is now deprecated anyway. I know, doesn't work is not a good problem description, but currently I'm not able to debug it under android. Under Windows, I see that the event handler continues correctly after the .Release and after it finished, my log message inside my controls

message sent to deallocated instance using Pinterest SDK

China☆狼群 提交于 2019-12-21 17:55:58
问题 I'm using the Pinterest iOS SDK to share an item in my iPad app. The following snippet of code will always crash with a message sent to deallocated instance on the line with the comment: NSString *clientId = [NSMutableString stringWithString:@"1431665"]; NSLog(@"clientId: %@", clientId); Pinterest *pinterest = [[Pinterest alloc] initWithClientId:clientId]; NSLog(@"gone: %@", clientId); // <- CRASH! I'm using NSMutableString stringWithString to simulate the conditions in my app. I don't

stringWithFormat vs initWithFormat under ARC

你说的曾经没有我的故事 提交于 2019-12-21 17:51:47
问题 stringWithFormat: is a class method of NSString , and returns an autoreleased string; initWithFormat: is an instance method, and before ARC the programmer had to take care of the returned object's memory management. If we have ARC turned on, what is the difference between the two methods? 回答1: With ARC, these two methods are equivalent. See: WWDC 2011 Session Video - Introducing Automatic Reference Counting WWDC 2011 Session Video - Objective-C Advancements In-Depth (explains how ARC code

When and why would I want to declare a local variable as __weak using ARC?

蹲街弑〆低调 提交于 2019-12-21 17:24:41
问题 Mike Ash has written this introduction to ARC where he introduces something like: __weak Foo *_weakFoo = [object foo]; Why would I want to do that for a local, temporary variable? __weak is a zeroing reference which will set the _weakFoo pointer automatically to nil as soon as the referenced object gets deallocated. Also, __weak is only available in iOS >= 5. When would I run into trouble when I simply do this?: Foo *_weakFoo = [object foo]; This is always expected to return an object or nil.

Objective C UIImagePNGRepresentation memory issue (using ARC)

我与影子孤独终老i 提交于 2019-12-21 12:13:45
问题 I have an ARC based app which loads about 2,000 fairly large (1-4MB) Base64 encoded images from a webservice. It converts the Base64 decoded strings to .png image files and saves them to the disk. This is all done in a loop where i shouldn't have any lingering references. I profiled my app and found out that UIImagePNGRepresentation was hogging around 50% of available memory. The way i see it, UIImagePNGRepresentation is caching the images it creates. One way to fix this would be to flush

Which iOS classes that don't support zeroing weak references?

南楼画角 提交于 2019-12-21 11:54:46
问题 Is there a list of classes in iOS that can't be referred with a __weak pointer when using automatic reference counting (ARC)? Apple's Transitioning to ARC Release Notes only lists Mac classes so far: Which classes don’t support zeroing-weak references? You cannot currently create zeroing-weak references to instances of the following classes: NSATSTypesetter , NSColorSpace , NSFont , NSFontManager , NSFontPanel , NSImage , NSMenuView , NSParagraphStyle , NSSimpleHorizontalTypesetter ,

When is NS_RETURNS_RETAINED needed?

删除回忆录丶 提交于 2019-12-21 08:26:09
问题 Take the below example: - (NSString *)pcen NS_RETURNS_RETAINED { return (__bridge_transfer NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (__bridge CFStringRef) self, NULL, (CFStringRef) @"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8); } Is it correct to put the NS_RETURNS_RETAINED there? Another example: + (UIImage *)resizeImage:(UIImage *)img toSize:(CGSize)size NS_RETURNS_RETAINED { UIGraphicsBeginImageContextWithOptions(size, NO, 0.0); [img drawInRect:...]; UIImage *resizedImage