I have some code that is causing memory leaks on an iOS static library. Here is an object's lifetime from Instruments:
# Category Event Type Timestamp RefCt Address Size Responsible Library Responsible Caller
0 Table_ColumnListener Malloc 4712087040 1 0x5e5fe60 16 Tests -[Table _initWithRows:andColumns:andTupleType:]
1 Table_ColumnListener Retain 4712301056 2 0x5e5fe60 0 Tests -[AbstractColumn addColumnListener:]
2 Table_ColumnListener Retain 4712453120 3 0x5e5fe60 0 Tests -[AbstractColumn addColumnListener:]
3 Table_ColumnListener Retain 4712602112 4 0x5e5fe60 0 Tests -[AbstractColumn addColumnListener:]
4 Table_ColumnListener Retain 4712755968 5 0x5e5fe60 0 Tests -[AbstractColumn addColumnListener:]
5 Table_ColumnListener Retain 4712915968 6 0x5e5fe60 0 Tests -[AbstractColumn addColumnListener:]
6 Table_ColumnListener Retain 4713062144 7 0x5e5fe60 0 Tests -[AbstractColumn addColumnListener:]
7 Table_ColumnListener Retain 4729644288 8 0x5e5fe60 0 Tests -[AbstractColumn removeColumnListener:]
/\
This is what confuses me
8 Table_ColumnListener Release 4729646080 7 0x5e5fe60 0 Tests -[AbstractColumn removeColumnListener:]
9 Table_ColumnListener Release 4729647872 6 0x5e5fe60 0 Tests -[AbstractColumn removeColumnListener:]
10 Table_ColumnListener Retain 4729679104 7 0x5e5fe60 0 Tests -[AbstractColumn removeColumnListener:]
11 Table_ColumnListener Release 4729680896 6 0x5e5fe60 0 Tests -[AbstractColumn removeColumnListener:]
12 Table_ColumnListener Release 4729682944 5 0x5e5fe60 0 Tests -[AbstractColumn removeColumnListener:]
13 Table_ColumnListener Retain 4729713152 6 0x5e5fe60 0 Tests -[AbstractColumn removeColumnListener:]
14 Table_ColumnListener Release 4729714944 5 0x5e5fe60 0 Tests -[AbstractColumn removeColumnListener:]
15 Table_ColumnListener Release 4729717248 4 0x5e5fe60 0 Tests -[AbstractColumn removeColumnListener:]
16 Table_ColumnListener Release 4729731840 3 0x5e5fe60 0 Tests -[Table dealloc]
Here is the code for [AbstractColumn addColumnListener:]
-(void) addColumnListener:(id <ColumnListener>)listener
{
[m_listeners addObject:listener];
}
And for [AbstractColumn removeColumnListener:]
-(void) removeColumnListener:(id <ColumnListener>)listener
{
[m_listeners removeObject:listener];
}
When I remove the object from the NSMutableArray
, it seems to increase the retain count instead of decrementing it. Has anyone else had this problem and knows of a solution?