현재 메모리 누수를 겪고 있으며 마지막으로 남긴 것들 중 하나를 해결하는 데 심각한 문제가 있습니다. 누설 도구는 NSCFString, NSMutableArray 및 GraphData라는 클래스에서 주로 발생하는 다양한 이유로 인해 같은 메서드에서 여러 누수가 발생하는 것을 보여줍니다. 나는 소용이없는 몇 가지 다른 방법으로 그것을 고치려고 노력했기 때문에 희망적으로 간과 한 단순한 무언가가이 문제에 관해 밝혀 질 수 있기를 희망한다. 내 게시물을보고에 대한메모리 누수 sqlite iOS 응용 프로그램
// the offending, leaking method
-(NSMutableArray*)fillDataInArray:(NSInteger)keyphrase_id{
NSLog(@"Keyphrase_id:%d", keyphrase_id);
NSDate *startdate = [self getDateForApplicationInstalled];
NSDate *enddate = [NSDate date];
NSString *dateString1=[[NSString alloc] initWithString: [fmt stringFromDate:startdate]];
NSString *dateString2=[[NSString alloc] initWithString: [fmt stringFromDate:enddate]];
NSMutableArray *newDataNew = [[NSMutableArray alloc]init];
self.newData = newDataNew;
[newDataNew release];
selStmt = nil;
if (!selStmt)
{
const char *sql = "select distinct position, key_time from ranking where keyphrase_id = ? and key_time between ? and ? order by key_time";
if (sqlite3_prepare_v2(database, sql, -1, &selStmt, NULL) != SQLITE_OK)
{
selStmt = nil;
}
NSInteger n = keyphrase_id;
sqlite3_bind_int(selStmt, 1, n);
sqlite3_bind_text(selStmt, 2, [dateString1 UTF8String] , -1, SQLITE_TRANSIENT);
sqlite3_bind_text(selStmt, 3, [dateString2 UTF8String] , -1, SQLITE_TRANSIENT);
NSLog(@"SQL query is: [%s]", sql);
}
if (!selStmt)
{
NSAssert1(0, @"Can't build SQL to read keyphrases [%s]", sqlite3_errmsg(database));
}
int ret;
while ((ret=sqlite3_step(selStmt))==SQLITE_ROW)
{
GraphData *item = [[GraphData alloc]init];
item.key = sqlite3_column_int(selStmt, 0);
item.value = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selStmt,1)];
[newData addObject:item];
[item release], item = nil;
}
sqlite3_reset(selStmt); // reset (unbind) statement
[dateString2 release];
[dateString1 release];
return newData;
}
//GraphData.h
@interface GraphData : NSObject{
NSInteger key;
NSString *value;
}
@property (nonatomic, readwrite) NSInteger key;
@property (nonatomic, retain) NSString *value;
-(id)initWithPrimaryKey:(NSInteger) xid;
-(id)initWithName:(NSString *)n key:(NSInteger)i;
@end
//GraphData.m
#import "GraphData.h"
@implementation GraphData
@synthesize key,value;
-(id)initWithPrimaryKey:(NSInteger) xid{
self.key = xid;
self.value = @"";
return self;
}
-(id)initWithName:(NSString *)n key:(NSInteger)i{
self.key = 0;
self.value = n;
return self;
}
-(void)dealloc{
[value release], value = nil;
[super dealloc];
}
@end
감사 : 여기
은 일부 코드입니다!
메서드 호출자는 메서드 호출의 반환 값을 보유하고있는 것 같습니다. 따라서 해당 응답의 머리에 못을 박았을 것입니다. 그러나 나는 집에 돌아간 이후로 내일 확인해야 할 것이다. 그래도 고마워! – Jace