title: Core data entity array generate crash on release or remove objects in IOS
body: <p>This is my <code>CoreDataManagerClass</code>.</p>
  
  <pre><code>#import &lt;Foundation/Foundation.h&gt;
  #import &lt;CoreData/CoreData.h&gt;
  @interface RTC_CoreDataManager : NSObject
  @property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
  @property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
  @property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
    - (void)saveContext;
    - (NSURL *)applicationDocumentsDirectory;
    -(void)insertEntity:(NSString *)entityName arrayOfManagedObject:(NSMutableArray *)array;
    +(RTC_CoreDataManager *)shredInstance;
     @end
  
  #import "RTC_CoreDataManager.h"
  RTC_CoreDataManager *obj_RTC;
  @implementation RTC_CoreDataManager
  
  @synthesize managedObjectContext = __managedObjectContext;
  @synthesize managedObjectModel = __managedObjectModel;
  @synthesize persistentStoreCoordinator = __persistentStoreCoordinator;
  
   - (void)saveContext
   {
   NSError *error = nil;
    NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
  if (managedObjectContext != nil) {
   if ([managedObjectContext hasChanges] &amp;&amp; ![managedObjectContext save:&amp;error]) {
  
             NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
             abort();
          }
     }
  }
  
  +(RTC_CoreDataManager *)shredInstance{
  if (obj_RTC ==  nil) {
             obj_RTC = [[RTC_CoreDataManager alloc]init];
         }
          return obj_RTC;
  
      }
  #pragma mark - Core Data stack
  
  
  - (NSManagedObjectContext *)managedObjectContext
  {
     if (__managedObjectContext != nil) {
          return __managedObjectContext;
    }
  
     NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
     if (coordinator != nil) {
         __managedObjectContext = [[NSManagedObjectContext alloc] init];
         [__managedObjectContext setPersistentStoreCoordinator:coordinator];
     }
     return __managedObjectContext;
  }
  
  
  - (NSManagedObjectModel *)managedObjectModel
  {
      if (__managedObjectModel != nil) {
          return __managedObjectModel;
      }
      NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"RTC" withExtension:@"momd"];
      __managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
      return __managedObjectModel;
  }
  
  
  - (NSPersistentStoreCoordinator *)persistentStoreCoordinator
   {
       if (__persistentStoreCoordinator != nil) {
          return __persistentStoreCoordinator;
     }
  
      NSURL *storeURL = [[self applicationDocumentsDirectory]     URLByAppendingPathComponent:@"RTC.sqlite"];
      NSError *error = nil;
      if (![[NSFileManager defaultManager] copyItemAtURL:storeURL toURL:[NSURL alloc] error:&amp;error]) {
          NSLog(@"Oops, could copy preloaded data");
      }
  
  __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
  if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&amp;error]) {
              NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
      abort();
  }
  
  return __persistentStoreCoordinator;
  }
  
  #pragma mark - Application's Documents directory
  
  // Returns the URL to the application's Documents directory.
  - (NSURL *)applicationDocumentsDirectory
  {
      return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
  }
  
  -(void)insertEntity:(NSString *)entityName arrayOfManagedObject:(NSMutableArray *)array 
  {
  NSManagedObjectContext *backgroundMOC = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
  for (id object in array)
   {
  
   [backgroundMOC performBlockAndWait:^
   {
   NSError *error;
   if (![__managedObjectContext save:&amp;error]) 
   {
  NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
  }
  }];
  }
  
  }
  
  @end
  </code></pre>
  
  <p>And this is my code in another controller.</p>
  
  <pre><code>    -(void)viewDidLoad
      {
       [super viewDidLoad];
       appDele_Obj = (RTC_AppDelegate *)[[UIApplication sharedApplication] delegate];
     appDele_Obj.entityArray=[[NSMutableArray alloc]init];
  
  for (int i=0; i&lt;10; i++)
  {
  
      Survey *objSurvey = [NSEntityDescription
                           insertNewObjectForEntityForName:@"Survey"
                           inManagedObjectContext:[RTC_CoreDataManager shredInstance].managedObjectContext];        [objSurvey setFirstName:@"1"];
      [objSurvey setLastName:@"2"];
      [objSurvey setEmpId:@"3"];
      [objSurvey setLanguage:@"Hindi"];
      [objSurvey setCountry:@"India"];
      [objSurvey setSurveyNo:[NSNumber numberWithInt:2]];
      [[appDele_Obj entityArray] addObject:objSurvey];
      [objSurvey release];
  }
  //[objSurvey release];
  [[RTC_CoreDataManager shredInstance] insertEntity:@"Survey" arrayOfManagedObject:[appDele_Obj entityArray]];
  if ([[appDele_Obj entityArray]count]  &gt;0) {
      [[appDele_Obj entityArray] removeAllObjects];
  
  }
  }
  </code></pre>
  
  <p>So My question is,<br>
  If I call method removeAllObjects on <code>[appDele_Obj entityArray]</code> crashing the application. Why I can not call <code>[[appDele_Obj entityArray] removeAllObjects];</code>
  in above approach. Any one can help me to solve this crash.</p>
  
  <p>Thanks.</p>