automatic-ref-counting

Using alloc, init in ARC enabled projects

怎甘沉沦 提交于 2019-12-05 06:43:28
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:@"Something"]; But which type I need to use exactly for ARC enabled project ? What will happen if I use first

iOS - beginning iOS tutorial - underscore before variable?

家住魔仙堡 提交于 2019-12-05 05:14:30
I am starting to learn how some iOS development at the minute and I currently have the Apress beginning IOS6 book that I am working off. In chapter two there is a simple tutorial to show two buttons and a label and when a button is pressed it is shown on the label which one was pressed. I have completed the tutorial but it has raised one question that I can't find the answer to. The tutorial uses ARC (automatic reference counting) in case that makes a difference. Here is the code, The header file: #import <UIKit/UIKit.h> @interface MTMViewController : UIViewController @property (weak,

ARC, bridged cast and GHUnit

百般思念 提交于 2019-12-05 04:52:33
I'm followinng tutorial from http://gabriel.github.com/gh-unit/docs/appledoc_include/guide_testing.html . The problem is that my project uses ARC and GHUnit doesn't. I managed previous errors, but now i should do bridged cast, that i've never used, and i'm lost. NSString *string1 = @"a string"; GHAssertNotNULL(string1, nil); //error here Error description: Implicit conversion of Objective-C pointer type 'NSString *' to C pointer type 'const void *' requires a bridged cast. Any help welcome :) joseph.hainline Since you are comparing an NSString, you should use the GHAssertNotNil check. See NULL

init] in automatic reference counting

天大地大妈咪最大 提交于 2019-12-05 04:51:47
问题 I know that I am suppose to use: ObjectClass *tmpObject = [[ObjectClass alloc] init]; realObject = tmpObject; [tmpObject release] to initialise realObject (where realObject is an object within a class) But now with ARC mode, releasing is automatic, do i still need to use this technique? Can I simply use realObject = [[ObjectClass alloc] init]; ? If not is there any specific reason why it would leak? Thanks 回答1: As Spencer said, if you compile with ARC enabled, you cannot call release at all.

Why doesn't ARC free memory when using [NSDate date] but works fine using [[NSDate alloc] init]?

混江龙づ霸主 提交于 2019-12-05 04:10:24
I've written some Objective-C application that seems to work fine, except for an ever-growing memory footprint. I'm using ARC under the last version of Xcode 4.6.2. My system is 10.7.5. I'm very new to Objective-C and need some help figuring out what's going on with my memory. I've narrowed down the problem to explaining why the following basic piece of code behaves like it does. This code is added in the vanilla Cocoa-based application template that Xcode gives (ARC enabled). Case A - (void)applicationDidFinishLaunching:(NSNotification *)aNotification{ NSDate* d; for(int i=0; i<1000000; i++){

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

家住魔仙堡 提交于 2019-12-05 03:39:26
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 来源: https://stackoverflow.com/questions/46842577/how-in-swift-to-know-that-struct-is-deleted-from-memory

difference between ARC and MRC

不想你离开。 提交于 2019-12-05 03:27:24
I am confused with Apple material. In 3 ways we manage the memory, they are : automatic referance counting. manual reference counting. garbage colletion. My doubt is what is the difference between automatic reference counting and manual referance counting. Can someone explain me ? In ARC you don't have to release/autorelease the memory allocated by you where as in case of manual you have to take care of this. e.g. manual case -(void)someMethod { NSMutableArray *arr = [[NSMutableArray alloc] init]; //use array [arr release]; //when array is in no use } ARC case -(void)someMethod {

Xcode Convert to ARC, Create universal binary fails with error of “can't figure out the architecture type of”

℡╲_俬逩灬. 提交于 2019-12-05 03:24:46
I'm attempting to convert an iOS (pure Objective-C) project to ARC. The conversion fails at the octest target CreateUniversalBinary stage with the following error. The project and target architecture build settings look correct to me so I am struggling to understand why this is failing: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/lipo: can't figure out the architecture type of: /Users/andybowskill/Library/Developer/Xcode/DerivedData/Make-Up_Kit-axtbxqtkmnlfmlcafkoetwqmeufc/Build/Intermediates/Make-Up Kit.build/Debug-iphoneos/Make-Up KitTests.build

Memory problems when pushing many view controllers on UINavigationController

孤者浪人 提交于 2019-12-05 02:51:47
问题 I'm making an interactive book for the iPad and am using UINavigationController to implement the navigation between a page and the next. When a user turns the page, the next page is pushed on top of the navigation stack. I'm now 15 pages into the app, and the app crashes when I try to go from page 14 to page 15. No error message in the console, nothing in the device's crash logs neither. Each view controller's scene in the storyboard has UIImageViews displaying images that are between 5MB and

What's the right way to set an NSError outparam from inside an autoreleasepool block?

江枫思渺然 提交于 2019-12-05 02:44:51
I have a method like this: - (void)processAThing:(id)thing error:(NSError * __autoreleasing *)error { @autoreleasepool { // Start processing. // Find some partway through error.. if (error) { *error = [NSError errorWithDomain...]; return NO; } // More processing. } } This is broken and crashes, because the NSError is autoreleased, and when the return happens, the pool is drained, so the thing that the caller gets is now bogus. I know I could significantly redesign the method so I collect all error cases outside the autorelease block, but I want to understand whether there's a correct way of