Saturday, May 02, 2009

Be careful of constructor helper methods

I forgot that constructor helper methods (e.g. +arrayWithCapacity) would make the array autoreleased leading to an EXC_BAD_ACCESS. Still getting used to the reference counting mechanism and conventions :).

I was using such a method for an instance variable. The solution was either to retain it or to use the alloc method, which gives you an object with a retain count of 1.

_replayLines = [[NSMutableArray alloc] initWithCapacity:5];

No comments: