Note that there are some explanatory texts on larger screens.

plurals
  1. POMemory Management Headache
    text
    copied!<p>I get leaks if I dont put it in dealloc. I get a crash <code>EXC_BAD_ACCESS</code> If I do. I cannot see anything wrong with this code. The bad access is pointed at <code>[events release]</code>. Have I made a mistake in the code below or is Instruments just having a laugh at my expense?</p> <p><code>events</code> is an <code>NSArray</code></p> <pre><code>@interface EventsViewController : UITableViewController { @private NSArray *events; } - (void)viewDidLoad { events = [[self getEvents] retain]; } - (void)dealloc { [events release]; [super dealloc]; } - (NSArray*)getEvents { NSMutableArray *response = [[[NSMutableArray alloc] init] autorelease]; //Some sql while(sqlite3_step(statement) == SQLITE_ROW) { Event *event = [[[Event alloc] init] autorelease]; event.subject = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)]; [response addObject:event]; } return response; } </code></pre> <p><strong>Update</strong> A lot of you are saying the code is fine which is a plus. I dont manipulate <code>events</code> elsewhere - I have removed any code that does to try and single out the crash. Perhaps its in the parent view?</p> <p>This is the click event that pushes the EventsViewController: - (void)eventsClick:(id)sender</p> <pre><code>{ EventsViewController *eventsViewController = [[EventsViewController alloc] initWithNibName:@"EventsViewController" bundle:nil]; eventsViewController.anywhereConnection = anywhereConnection; eventsViewController.contact = contact; [[self navigationController] pushViewController:eventsViewController animated:YES]; [eventsViewController release]; } </code></pre> <p>The crash is actually happening when I return to the parent view. (I think it is considered a parent in this scenario). But perhaps the <code>[eventsViewController release]</code> just triggers <code>dealloc</code> in the <code>EventViewController</code>. </p>
 

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