automatic-ref-counting

Encode and Decode CGMutablePathRef with ARC

淺唱寂寞╮ 提交于 2019-12-08 09:46:08
问题 Under ARC, is it possible to encode/decode a CGMutablePathRef (or its non-mutable form) using NSCoding ? Naively I try: path = CGPathCreateMutable(); ... [aCoder encodeObject:path] but I get a friendly error from the compiler: Automatic Reference Counting Issue: Implicit conversion of an Objective-C pointer to 'CGMutablePathRef' (aka 'struct CGPath *') is disallowed with ARC What can I do to encode this? 回答1: NSCoding is a protocol. Its methods can only be used with objects that conform to

Using blocks and ARC is causing a “message sent to deallocated instance” error

老子叫甜甜 提交于 2019-12-08 09:17:47
问题 I had a problem with ARC and blocks but have solved the problem. Unfortunately I don't what exactly is going on and would like to learn more about the situation I had. Originally, I had code that did this for(__block id<Foo> object in objects) { foo download:someParm success:^{ object.state = StateNewState; } ]; } This caused an imbalance in retains. A crash occurs when an object is accessed and is said to be already deallocated. I wrote a class that implemented and used the "copy" attribute

Xcode App doesn't release memory

前提是你 提交于 2019-12-08 09:16:30
问题 I'm creating an app which stores images in the device (save it as coreData) and I have a problem. every time I choose a picture to add the the collectionView, the memory increases in 100Mb or so, and it increases every time. I think I added the ARC , (Edit->refactor->convert to objective-c ARC..) and it doesn't seem to have any problem adding it, but still the memory doesn't release. Here is my code when image is chosen by the user in uiimagepicker: - (void)imagePickerController:

Using methods from non-ARC libraries in an ARC project?

随声附和 提交于 2019-12-08 07:37:31
问题 I am using the excellent, however, non-ARC project: https://github.com/boredzo/iso-8601-date-formatter I am trying to use the following method from this library which is non-ARC in an ARC project: - (NSDate *) dateFromString:(NSString *)string timeZone:(out NSTimeZone **)outTimeZone; I have tried: group.updatedAt = [formatter dateFromString:someString timeZone:[NSTimeZone localTimeZone]]; group.updatedAt = [formatter dateFromString:someString timeZone:*__autorelease [NSTimeZone localTimeZone]

Objective-C - autoreleasepool (ARC - Automatic reference Counting)

江枫思渺然 提交于 2019-12-08 05:34:22
问题 I have a doubt regarding autoreleasepool in an Auto Reference Counting (ARC) In my example (pasted below) I have an autoreleasepool and I have no statements within the autoreleasepool block. There is an autoreleased instance (a3) after the autoreleasepool block. Expected Behavior: I expected the following statement to cause a memory leak because it is not encapsulated with in an autoreleasepool. A* a3 = b1.xa1; Actual Behavior: Actual behavior is that no memory leak error is thrown at runtime

Core Plot and Xcode 5.1 - How to convert Core Plot to ARC?

三世轮回 提交于 2019-12-08 03:31:04
问题 I just installed Xcode 5.1 and found that it definitely requires projects to use ARC. I get error: garbage collection is no longer supported when trying to compile Core Plot (version 1.4). Out of curiosity I told Xcode to convert Core Plot to ARC. But it fails with ARC forbids Objective-C objects in struct in file CPTPlatformSpecificFunctions.m . I don't want to dive into Core Plot and break something by trying to fix this or similar errors. Is there a compiler setting I have overlooked? Or

Objective-C ARC and longjmp

风流意气都作罢 提交于 2019-12-08 03:24:36
问题 What is the best practice for mixing Objective-C ARC with longjmp ? I am using Lua as scripting language, and my platform exports custom library for scripts. Entry points do check arguments with luaL_checkinteger(L, 2) (among others), which, in turn, may call luaL_typerror(L, 2, ...) , that is implemented in Lua with setjmp / longjmp . As far as I know, ARC simply auto-generates retain / release code, but what happens if it longjmp s out of scope? Will this code leak on mistyped arguments?

ARC warning: Implicit declaration of function 'DLog' is invalid in C99

扶醉桌前 提交于 2019-12-08 01:36:05
问题 I use DLog macro in an ARC project, and I got the warning: Implicit declaration of function 'DLog' is invalid in C99 You can find DLog from http://iphoneincubator.com/blog/debugging/the-evolution-of-a-replacement-for-nslog How to fix this warning? 回答1: I actually had this warning when calling Dlog without a capital L. I changed it into DLog and everything worked fine. But you seem to have it correct. 回答2: Make sure your Prefix.pch file is included in 'Build Settings' -> 'Prefix Header' 来源:

Using methods from non-ARC libraries in an ARC project?

坚强是说给别人听的谎言 提交于 2019-12-07 19:15:30
I am using the excellent, however, non-ARC project: https://github.com/boredzo/iso-8601-date-formatter I am trying to use the following method from this library which is non-ARC in an ARC project: - (NSDate *) dateFromString:(NSString *)string timeZone:(out NSTimeZone **)outTimeZone; I have tried: group.updatedAt = [formatter dateFromString:someString timeZone:[NSTimeZone localTimeZone]]; group.updatedAt = [formatter dateFromString:someString timeZone:*__autorelease [NSTimeZone localTimeZone]]; group.updatedAt = [formatter dateFromString:someString timeZone:(*__autoreleasing [NSTimeZone

Playing around with ARC: Force release irritation?

佐手、 提交于 2019-12-07 17:11:57
问题 I am currently playing around with ARC a bit to get some things figured out, before starting to do the actual work. I did setup this code: NSNumber* n = [[NSNumber alloc] initWithInt:3]; __weak NSNumber* weakN = n; n = nil; NSLog(@">>>: %@ %@", n, weakN); I expected n and weakN to be nil, as n = nil; should trigger a release in my eyes? Unfortunately it doesn't. The output is ">>>: (null) 3". What am I missing here? Another thing is, that I am pretty sure, the below code was giving me a hard