BlogApp has exited due to signal 11 (SIGSEGV).
By far the most common error I've been making in Objective-C is forgetting to retain objects that are autoreleased.
Case in point - I tried executing some SQL onto a database connection and the ObjectiveC runtime immediately crapped out on me with the above error.
What I had done is in the init block, I had code that looked like this:
static SQLDatabase* database
...
database = [SQLDatabase databaseWithFile:path];
The database object is in the autorelease pool since I didn't explicitly invoke the alloc/init mesage handlers. Crap.
The fix is simple of course:
database = [[SQLDatabase databaseWithFile:path] retain];
and all is well in the world.
This isn't quite the same as a NullPointerException in Java though. I forgot to make the database connection at all initially, and I only saw the problem because a unit test failed - invalid number of returned rows. Why? Because Objective-C handles null objects properly so any method I invoked on nil just becomes a no-op.
So - what does this mean?
Note to self:
1. write more unit tests.
2. learn from stupid mistakes faster
5:59:03 PM
|