Note that there are some explanatory texts on larger screens.

plurals
  1. POdealloc crash on retained array. Program received signal: “EXC_BAD_ACCESS”
    primarykey
    data
    text
    <p>I am stuck on a EXC_BAD_ACCESS” crash within my dealloc of a table view controller. The crash occurs when releasing an NSMutableArray that was given a retain property. I have a second NSMutableArray that was also given a retain property, but it's release does not cause a crash. Please take a look at the following code to see if I am overlooking something about memory management. Thanks.</p> <p>In my header file, I have the following:</p> <pre><code>@interface selectSourcesTableViewController : UIViewController &lt;UITableViewDelegate, UITableViewDataSource&gt; { NSMutableArray *selectedNames; NSMutableArray *selectedAvailability; } @property (retain, nonatomic) NSMutableArray *selectedNames; @property (retain, nonatomic) NSMutableArray *selectedAvailability; </code></pre> <p>In my implementation, I have the following:</p> <pre><code>@implementation selectSourcesTableViewController @synthesize selectedNames; @synthesize selectedAvailability; - (void)viewDidLoad { NSArray *names = [selectedSourceFileContent objectForKey:@"selectedNames"]; selectedNames = [[NSMutableArray alloc] initWithObjects: nil]; NSArray *availability = [selectedSourceFileContent objectForKey:@"selectedAvailability"]; selectedAvailability = [[NSMutableArray alloc] initWithObjects: nil]; for (int i=0; i &lt; [names count]; i++) { NSString *aName = [names objectAtIndex:i]; [selectedNames addObject: aName]; NSString *anAvailability = [availability objectAtIndex:i]; [selectedAvailability addObject: anAvailability]; } } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: kCellIdentifier]; ... for (int i=0; i &lt; [selectedNames count]; i++) { if ([contentForThisRow isEqualToString:[selectedNames objectAtIndex:i]]) { cell.accessoryType = UITableViewCellAccessoryCheckmark; } } } - (void)dealloc { [super dealloc]; [selectedNames release]; [selectedAvailability release]; } </code></pre> <p>The code shown above shows the only uses of these two arrays.</p> <p>So, nothing bad happens when selectedNames is released, but I get a EXC_BAD_ACCESS crash when selectedAvailability is released.</p> <p>One last observation. There is no crash the very first time I run this code after launching xcode. Thereafter, it crashes every time I rerun the app.</p> <p>Any thoughts?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload