Error : EXC_Bad_Access while accessing a retainCount of an Object <p>In header file .h</p> <pre><code>@interface MemoryAppDelegate:NSObject &lt;UIApplicationDelegate&gt; { Class1 *class1_obj; } </code></pre> <p>In Implementation file .m</p> <pre><code>@implementation Memory : (UIApplication*) application { NSLog(@"Retain Count of class1_obj %d",[class1_obj retainCount]); //ouput retainCount is 0 Class2 *class2_obj; NSLog(@"Retain Count of class2_obj %d",[class2_obj retainCount]); // gives EXC_Bad_Access error </code></pre> <p>As in the above code, when I declare a object in header file and try to access its retain count is gives me 0. But if I declare the object in implementation file and access its retainCount it throws Bad_Access. Kindly can you say why this error occurs?</p>