automatic-ref-counting

iOS: How to remove object from memory with ARC enabled?

天涯浪子 提交于 2019-11-29 02:00:17
I am developing an iOS app with the iOS 5 SDK, Automatic Reference Counting is enabled. But I have a specific object that is being created in large numbers and must be released after a second because otherwise the device will become very slow. It looks like they are not released, as the device is very slow. Is there a way to manually release an object when ARC is enabled? EDIT: My code, this is called 200 times a second to generate sparkles. They fade out after 0.8 seconds so they are useless after then. int xanimationdiff = arc4random() % 30; int yanimationdiff = arc4random() % 30; if

ARC circular retain detection

不羁的心 提交于 2019-11-29 01:37:25
问题 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! 回答1: The

I'm writing a Button class in Objective-C with ARC — How do I prevent Clang's memory leak warning on the selector?

浪尽此生 提交于 2019-11-29 01:19:08
I'm writing a simple button class, something like this: @interface MyButton : NSObject { id object; SEL action; } @property(strong) id object; @property SEL action; -(void)fire; @end @implementation MyButton @synthesize object, action; -(void)fire { [object performSelector:action]; } @end I get the following warning from Clang on [object performSelector:action] : PerformSelector may cause a leak because its selector is unknown After some research I see that selectors can belong to families which have different memory requirements. The intention is for the action to return void, so it shouldn't

Reduce Peak Memory Usage With @autoreleasepool

£可爱£侵袭症+ 提交于 2019-11-29 01:12:24
问题 I work on an iPad application that has a sync process that uses web services and Core Data in a tight loop. To reduce the memory footprint according to Apple's Recomendation I allocate and drain an NSAutoreleasePool periodically. This currently works great and there are no memory issues with the current application. However, I plan on moving to ARC where the NSAutoreleasePool is no longer valid and would like to maintain this same kind of performance. I created a few examples and timed them

How to enable/ disable “Automatic Reference Counting”?

拈花ヽ惹草 提交于 2019-11-29 01:00:07
Using Xcode 4.2, how can one enable/disable "Automatic Reference Counting"? ANSWERED Under Build Settings, flip "yes" and "no" depending whether you want ARC enabled. Globally: Go to "Build Settings", look for "Apple LLVM compiler 3.0 - Language". Set the field "Objective-C Automatic Reference Counting" to "No". For individual files: Go to "Build Phases", select the file, double-click the "Compiler Flags" column and put "-fno-objc-arc" in it. To enable ARC per-file, you can also set your "Compiler Flags" under "Build Phases" to -fobjc-arc . Make sure your compiler is set to Apple LLVM compiler

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

ⅰ亾dé卋堺 提交于 2019-11-29 00:36:18
问题 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

Could i build a ARC framework and use it in a non-ARC project?

牧云@^-^@ 提交于 2019-11-29 00:01:15
I think the title explains my question pretty well, I'm currently working on a small framework for my personal needs, and thought about building it with ARC (if thats possible at all?), and use it in old projects that were built before ARC? Yes, with one caveat: if you have iOS 4.x as a deployment target, a supplemental library is necessary to deal with ARC-compiled code on the older runtime. For an application built using ARC, this is packaged in with the application. This is not included if you are using an ARC-compiled library in a non-ARC application. You can manually link this library

How to properly implement ARC compatible and `alloc init` safe Singleton class? [duplicate]

本小妞迷上赌 提交于 2019-11-28 23:19:06
问题 This question already has an answer here: How do I implement an Objective-C singleton that is compatible with ARC? 10 answers I saw thread safe version +(MyClass *)singleton { static dispatch_once_t pred; static MyClass *shared = nil; dispatch_once(&pred, ^{ shared = [[MyClass alloc] init]; }); return shared; } but what would happen if someone just calls [MyClass alloc] init] ? How to make it return same instance as the +(MyClass *)singleton method? 回答1: Apple recommends the strict singleton

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

筅森魡賤 提交于 2019-11-28 22:57:51
问题 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

The role of -supportsWeakPointers

若如初见. 提交于 2019-11-28 22:57:45
问题 Apple have recently published Transitioning to ARC Release Notes, a document that explains ARC and tackles some of the issues of converting non-ARC code to ARC. In these notes, they mention the following: If you you [sic] find that you must implement custom retain or release methods, then you must also implement the following method in your class: -(BOOL)supportsWeakPointers { return NO; } This method will prevent weak pointers from being formed to your objects. You are strongly encouraged to