title: @property retain OR copy
body: <p>First I read this <a href="https://stackoverflow.com/questions/387959/nsstring-property-copy-or-retain">article</a></p>
  <p>I think I should use &quot;copy&quot; in my programe.
  Problem is using NSMutableDictionary copy it will terminate.</p>
  <p>***** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFDictionary removeAllObjects]: mutating method sent to immutable object'**</p>
  <p>I have no idea about &quot;mutating method sent to immutable object&quot;.
  I didn't set NSDictionary to NSMutabledictionary pointer.</p>
  <p>Here is my code</p>
  <br/>
  <br/>
  <p>.h file</p>
  <pre><code>@interface Button : NSObject {
  
  @private
      NSString*               gID;                                 
      NSString*               gBackColor;                          
      NSString*               gIconImage;                          
      int                     gIndex;                              
      BOOL                    gEnable;                            
      BOOL                    gVisible;
      NSString*               gText;
      
      NSMutableDictionary*    gEvents;
      
      
      BOOL                    gUseCircle;                 
  }
  
  @property (nonatomic,copy) NSString                 *ID;
  @property (nonatomic,copy) NSString                 *BackColor;
  @property (nonatomic,copy) NSString                 *IconImage;
  @property int Index;
  @property BOOL Enable;
  @property BOOL Visible;
  @property (nonatomic,copy) NSString                 *Text;
  @property (nonatomic,getter=getEvents,retain) NSMutableDictionary       *Events;
  @property BOOL UseCircle;
  
  @end
  </code></pre>
  <br/>
  <br/>
  <p>.m file</p>
  <pre><code>@implementation Button
  @synthesize ID = gID;
  @synthesize BackColor = gBackColor;
  @synthesize IconImage = gIconImage;
  @synthesize Index = gIndex;
  @synthesize Enable = gEnable;
  @synthesize Visible = gVisible;
  @synthesize Text = gText;
  @synthesize Events = gEvents;
  @synthesize UseCircle = gUseCircle;
  
  -(NSMutableDictionary*) getEvents
  {
      if (!gEvents) 
      {
          gEvents = [[NSMutableDictionary alloc] initWithCapacity:20];
      }
      return gEvents;
  }
  
  - (id) init
  {
      self = [super init];
      if (self != nil) 
      {
          gID = @&quot;&quot;;
          gBackColor = @&quot;&quot;;
          gIconImage = @&quot;&quot;;
          gIndex = 0;
          gText = @&quot;&quot;;
          
          gUseCircle = NO;
      }
      return self;
  }
  
  - (void) dealloc
  {
      [gID release];
      [gBackColor release];
      [gIconImage release];
      [gText release];
      
      [gEvents removeAllObjects];
      [gEvents release];
      gEvents = nil;
      
      [super dealloc];
  }
  </code></pre>
  <br/>
  <br/>
  <p>And implement</p>
  <pre><code>tBtnXML.Events = [self SplitEvents:tNode];
  </code></pre>
  <br/>
  <br/>
  <p>SplitEvents function:</p>
  <pre><code>-(NSMutableDictionary*) SplitEvents:(NSDictionary*)pEvents
  {
      NSMutableDictionary *tEvents = [[NSMutableDictionary alloc] initWithCapacity:5];
      // code blabla
      //.
      //.
      //.
      [tEvents setObject:tEvent forKey:[NSNumber numberWithInt:tEventName]];
      [tEvent release];
              
              
  
              return [tEvents autorelease];
  }
  </code></pre>
  <br/>
  <p>But I chage  NSMutableDictionary* gEvents property from copy to retain , it execute normal.</p>
  <p>Colud anyone tell me what's wrong with my code?</p>
  <p>If my code is incorrect with dealloc,please tell me.</p>
  <p>Thank you appriciate.
  <br/>
  <br/>
  <br/>
  <br/>
  <br/>
  <br/></p>
  <p>Yes, So I fixed my setter:</p>
  <pre><code>-(void) setEvents:(NSMutableDictionary*) pEvents
  {
      NSMutableDictionary* tNewDict = [pEvents mutableCopy];
      [gEvents removeAllObjects];
      [gEvents release];
      gEvents = tNewDict;
  }
  </code></pre>
  <br/>
  <p>This work with no error.</p>
  <p>It helps me a lot.</p>
  <p>But I can't vote up &gt;&quot;&lt;~</p>
  <p>So thank you Bavarious :)
  <br/><br/></p>