Search Results

Search found 4 results on 1 pages for 'psebos'.

Page 1/1 | 1 

  • should variable be released or not? iphone-sdk

    - by psebos
    Hi, In the following piece of code (from a book) data is an NSDictionary *data; defined in the header (no property). In the viewDidLoad of the controller the following occurs: - (void)viewDidLoad { [super viewDidLoad]; NSArray *keys = [NSArray arrayWithObjects:@"home", @"work", nil]; NSArray *homeDVDs = [NSArray arrayWithObjects:@"Thomas the Builder", nil]; NSArray *workDVDs = [NSArray arrayWithObjects:@"Intro to Blender", nil]; NSArray *values = [NSArray arrayWithObjects:homeDVDs, workDVDs, nil]; data = [[NSDictionary alloc] initWithObjects:values forKeys:keys]; } Since I am really new to objective-c can someone explain to me why I do not have to retain the variables keys,homeDVDs,workDVDs and values prior exiting the function? I would expect prior the data allocation something like: [keys retain]; [homeDVDs retain]; [workDVDs retain]; [values retain]; or not? Does InitWithObjects copies (recursively) all objects into a new table? Assuming we did not have the last line (data allocation) should we release all the NSArrays prior exiting the function (or we could safely assumed that all NSArrays will be autoreleased since there is no alloc for each one?) Thanks!!!!

    Read the article

  • when an autoreleased object is actually released?

    - by psebos
    Hi, I am new in objective-c and I am trying to understand memory management to get it right. After reading the excellent Memory Management Programming Guide for Cocoa by apple my only concern is when actually an autoreleased object is released in an iphone/ipod application. My understanding is at the end of a run loop. But what defines a run loop in the application? So I was wondering whether the following piece of code is right. Assume an object @implementation Test - (NSString *) functionA { NSString *stringA; stringA = [[NSString alloc] initWithString:@"Hello" autorelease] return stringA; } - (NSString *) functionB { NSString *stringB; stringB = [self functionA]; return stringB; } - (NSString *) functionC { NSString *stringC; stringC = [self functionB]; return stringC; } - (void)viewDidLoad { [super viewDidLoad]; (NSString *) p = [self functionC]; NSLog(@"string is %@",p); } @end Is this code valid? From the apple text I understand that the NSString returned from functionA is valid in the scope of functionB. I am not sure whether it is valid in functionC and in viewDidLoad. Thanks!

    Read the article

  • should variable be retained or not? iphone-sdk

    - by psebos
    Hi, in the following piece of code I got from a book. The NSString *pPath which is defined in the class as an instance variable. @interface MainViewController : UIViewController { NSString *pPath; } In the implementation after being set it is being retained. I assume that with the assignment the object is automatically retained (because it is an NSString) and there is no need to additionally retain it. - (void) initPrefsFilePath { NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; pPath = [documentsDirectory stringByAppendingPathComponent: @"flippingprefs.plist"]; [pPath retain]; }

    Read the article

  • should variable be released or not? iphone-sdk

    - by psebos
    Hi, I have the following piece of code from a book. There is this function loadPrefs where the NSString *userTimeZone is being released before the end of the function. Why? The string was not created with alloc and I assume that the stringForKey function returns an autoreleased NSString. Is this an error or am I missing something? Is it an error in the book? (I new into objective-C) In the documentation for stringForKey the only thing it mentions is: Special Considerations The returned string is immutable, even if the value you originally set was a mutable string. The code: - (void) loadPrefs { timeZoneName = DefaultTimeZonePref; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSString *userTimeZone = [defaults stringForKey: TimeZonePrefKey]; if (userTimeZone != NULL) timeZoneName = userTimeZone; [userTimeZone release]; show24Hour = [defaults boolForKey:TwentyFourHourPrefKey]; } Thanks!!!!

    Read the article

1