• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Newbie Q - Variables not being retained in class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie Q - Variables not being retained in class


  • Subject: Re: Newbie Q - Variables not being retained in class
  • From: Charlton Wilbur <email@hidden>
  • Date: Fri, 9 Sep 2005 13:52:17 -0400


On Sep 9, 2005, at 11:57 AM, Aaron Wallis wrote:

- ( void ) setupPreferences
{
NSMutableDictionary * defaultPrefs = [NSMutableDictionary dictionary];
[defaultPrefs setObject:@"%" forKey:@"ExpressionKey"];
[defaultPrefs setObject:@"(" forKey: @"ExpressionIn"];
[defaultPrefs setObject:@")" forKey:@"ExpressionOut"];


    myPrefs = [NSUserDefaults standardUserDefaults];
    [myPrefs registerDefaults : defaultPrefs];
}

You say [NSMutableDictionary dictionary], which produces an autoreleased NSMutableDictionary. It is guaranteed to be good for the context in which it's created, which means your - setObject:forKey: messages succeed. But at some point when control is returned to the run loop, the autorelease pool is emptied, which means that defaultPrefs is finally released and dealloc'd.


If you don't want this to happen, you need to retain it there and release it at some later point.

Charlton


-- Charlton Wilbur email@hidden email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Newbie Q - Variables not being retained in class (From: Aaron Wallis <email@hidden>)

  • Prev by Date: Re: Proper way of ending text field editing on Quit
  • Next by Date: Re: Newbie Q - Variables not being retained in class
  • Previous by thread: Re: Newbie Q - Variables not being retained in class
  • Next by thread: Newbie Q - Variables not being retained in class
  • Index(es):
    • Date
    • Thread