我目前有一個NSMutableArray類別,創建一個NSMutableArray與NSNulls傳播。當我運行在儀器這段代碼它告訴我,我有一個泄漏這裏(閱讀評論,看看那裏)泄漏NSMutableArray類別,返回數組充滿NSNull
#import "NSMutableArray+NSNull.h"
@implementation NSMutableArray (NSNull)
-(id)initWithNullCapacity:(int)capacity{
self = [super init];
if (self) {
//Leak on [self init]
NSMutableArray *array = [self init];
for (unsigned i = 0; i < capacity; i++)
{
[array addObject:[NSNull null]];
}
self = array;
}
return self;
}
編輯:
這是我調用的方法:
#import "TWVStatData.h"
#import "NSMutableArray+NSNull.h"
@implementation TWVStatData
@synthesize creationTime;
@synthesize graphs;
@synthesize elements;
@synthesize type;
-(id)init{
if(self == [super init]){
type = -1;
creationTime = [[NSDate alloc] init];
graphs = [[NSMutableArray alloc] initWithNullCapacity:3];
elements =[[NSMutableArray alloc] init];
}
return self;
}
當我做你的建議,儀器告訴我,我有一個線上自我= [selfinitWithCapacity:容量]泄漏; – Cyprian 2011-04-13 17:47:01
@Cyprian你能發佈使用這種方法的代碼嗎?真的不應該有什麼錯... – 2011-04-13 18:32:43
使用它的代碼張貼在我的問題編輯 – Cyprian 2011-04-13 18:34:16