title: Using Variable of AppDelegate as a Global Variable - question regarding release/retain
body: <p>I have created a Variable called "myDBManager" in my AppDelegate:</p>
  
  <pre><code>@interface myAppDelegate : NSObject &lt;UIApplicationDelegate&gt; {
     MyDBManager *myDBManager;
  }
  @property (nonatomic, retain)  MyDBManager *myDBManager;
  
  @end
  </code></pre>
  
  <p>which I use in most other classes as a global Variable holding all my critical application data. It gets only created once and dies at the end only. So for example to get to the myDBManager in AnyOtherClass</p>
  
  <pre><code>@interface AnyOtherClass :  UITableViewController {
     MyDBManager *myDBManager;
     NSObject *otherVar;
  }
  @property (nonatomic,retain)   MyDBManager *myDBManager;
  @property (nonatomic,retain)   NSObject *otherVar;
  @end
  
  //getting the data from "global" myDBManager and putting it into local var of AnyOtherClass
  - (void)viewWillAppear:(BOOL)animated {
     //get the myDBManager global Object
     MyAppDelegate *mainDelegate = (MyAppDelegate *)[[UIApplication sharedApplication]delegate];
     myDBManager = mainDelegate.myDBManager;
     }
  
  
  -  (void)dealloc {
         [otherVar release];
          //[dancesDBManager release]; DO NOT RELEASE THIS SINCE ITS USED AS A GLOBAL VARIABLE!
          [super dealloc];
          }
  </code></pre>
  
  <p>Here is my question: while all other local variables of AnyOtherClass, such as "otherVar" have to be released in the dealloc method of AnyOtherClass (always- is that right?), releasing myDBManager within AnyOtherClass leads to errors in the app. </p>
  
  <p>So I NEVER release the local myDBManager variable in any Class of my app - all other local variables are always released - and it works fine. (Even checking the retainCount).</p>
  
  <p>Am I right, that ALL local variables of classes need to be released in the dealloc of that class, or is it actually OK, not to release these variables at all in cases of using a global variable construct as described? (or any other cases?)</p>
  
  <p>Thanks very much for your help!</p>