我在我的目標C代碼中的內存泄漏有點麻煩。任何人都可以看一看,讓我知道他們在想什麼?iOS的NSMutableArray內存泄漏
NSStringArray.h
@interface NSStringArray : NSObject {
NSMutableArray *realArray;
}
@property (nonatomic, assign) NSMutableArray *realArray;
-(id)init;
-(void)dealloc;
@end
NSStringArray.m
#import "NSStringArray.h"
@implementation NSStringArray
@synthesize realArray;
-(id)init {
self = [super init];
if (self != nil) {
realArray = [[[NSMutableArray alloc] init] retain];
}
return self;
}
-(void)dealloc {
[realArray release];
realArray = nil;
[super dealloc];
}
Factory.m
+(NSStringArray *)getFields:(NSString *)line {
//Divides the lines into input fields using "," as the separator.
//Returns the separate fields from a given line. Strips out quotes & carriage returns.
line = [line stringByReplacingOccurrencesOfString:@"\"" withString:@""];
line = [line stringByReplacingOccurrencesOfString:@"\r" withString:@""];
NSStringArray *fields = [[NSStringArray alloc] init];
for (NSString *field in [line componentsSeparatedByString:@","]) {
[fields.realArray addObject:field];
[field release];
}
return [fields autorelease];
}
泄漏工具說,當字段被分配發生泄漏,當我將字段字符串添加到字段數組。
另外,這個函數正在調用我正在解析的文件的每一行。
任何提示將有所幫助。
謝謝!
這就是問題所在!非常感謝! –