Have problems with memory have code that looks like this:
Have EXC_BAS_ACCESS
@interface MapList : NSObject
{
NSArray* m_units;
}
-(MapList*) loadMapListWithLevel:(uchar) lvl chapter: (uchar) chapt;
-(void) dealloc;
@end
and implementation:
-(MapList*) loadMapListWithLevel:(uchar) lvl chapter: (uchar) chapt
{
self =[super init];
if (self)
{
{
...
NSMutableArray* array = [[NSMutableArray alloc] initWithCapacity:size];
for (uint j=0;j<size;j++)
{
obj =[[SpriteDB alloc] init];
[array addObject:obj];
[obj release];
}
if (i==0)
m_units = [NSArray arrayWithArray:array];
[array release];
}
...
}
return self;
}
-(void) dealloc
{
[m_units release];
[super dealloc];
}
And in one method I call them like this
MapList* mpl = [[MapList alloc] loadMapListWithLevel:level chapter:chapter];
[mpl release];
Where is problem? When I comment [m_units release]; it works…
m_units = [NSArray arrayWithArray:array];gives you an autoreleased value. When you do a second release, you are over releasing this object. Even accessing this value after the return of the runloop will give you memory problems. Retain this value, and release it on your dealloc. Also, you should use properties.