我发现 3 个函数存在严重泄漏,并且我一次又一次地调用这些函数
我一次又一次地使用 3 个函数,但每次都会出现泄漏。这些泄漏的原因是什么?
//function 1
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = appDelegate.Date_iCal;
localNotification.alertBody = appDelegate.Name;
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.applicationIconBadgeNumber = count;//total number of event in iCal
NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:@"Object 1", @"Key 1", @"Object 2", @"Key 2", nil];
localNotification.userInfo = infoDict;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
[localNotification release] ;
//Local notification add
function2:
EKEventStore *eventStore = [[EKEventStore alloc]init] ;
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = appDelegate.Name;
event.startDate = appDelegate.Date_iCal;
event.endDate = appDelegate.Date_iCal;
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
@try
{
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
NSString* str = [[NSString alloc] initWithFormat:@"%@", event.eventIdentifier];
appDelegate.eventIdentifier = str;
[str release];
}
@catch (NSException * e)
{
//NSLog(@"exeption run1");
}
[eventStore release];
//function3
int flag1 = 0;
if( [appDelegate.display_date length] == 0 || [appDelegate.timestamp1 length] == 0)
{
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"dd.MM.yyyy hh:mm a"];
appDelegate.display_date = [df stringFromDate:[NSDate date]];
appDelegate.timestamp1 = @"empty";
[df release];
}
addStmt1 = nil;
if(addStmt1 == nil)
{
const char *sql ="insert into actions(action_title,action_date,dificulty_level,subid,flag,needle_num,display_date,event) Values(?,?,?,?,?,?,?,?)";
if(sqlite3_prepare_v2(database1, sql, -1, &addStmt1, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database1));
}
sqlite3_bind_text(addStmt1, 1, [appDelegate.Name UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStmt1, 2, [appDelegate.timestamp1 UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_double(addStmt1, 3, appDelegate.dif_lev);
sqlite3_bind_int(addStmt1,4,(int)appDelegate.Id);
sqlite3_bind_int(addStmt1,5,flag1);
sqlite3_bind_int(addStmt1,6,(int)appDelegate.needle_num);
sqlite3_bind_text(addStmt1, 7, [appDelegate.display_date UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStmt1, 8, [appDelegate.eventIdentifier UTF8String], -1, SQLITE_TRANSIENT);
if(SQLITE_DONE != sqlite3_step(addStmt1))
{
@try
{
NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database1));
}
@catch (NSException * e)
{
//NSLog(@"exeption run3");
}
}
sqlite3_reset(addStmt1);
sqlite3_finalize(addStmt1);
if( [appDelegate.display_date isEqualToString:@"empty"])
appDelegate.display_date = @"";
我哪里出错了? 这些功能只需点击一键即可运行。
I am using 3 functions again and again but see leaks every time.What is the reason of these leaks?
//function 1
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = appDelegate.Date_iCal;
localNotification.alertBody = appDelegate.Name;
localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.applicationIconBadgeNumber = count;//total number of event in iCal
NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:@"Object 1", @"Key 1", @"Object 2", @"Key 2", nil];
localNotification.userInfo = infoDict;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
[localNotification release] ;
//Local notification add
function2:
EKEventStore *eventStore = [[EKEventStore alloc]init] ;
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = appDelegate.Name;
event.startDate = appDelegate.Date_iCal;
event.endDate = appDelegate.Date_iCal;
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
@try
{
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
NSString* str = [[NSString alloc] initWithFormat:@"%@", event.eventIdentifier];
appDelegate.eventIdentifier = str;
[str release];
}
@catch (NSException * e)
{
//NSLog(@"exeption run1");
}
[eventStore release];
//function3
int flag1 = 0;
if( [appDelegate.display_date length] == 0 || [appDelegate.timestamp1 length] == 0)
{
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"dd.MM.yyyy hh:mm a"];
appDelegate.display_date = [df stringFromDate:[NSDate date]];
appDelegate.timestamp1 = @"empty";
[df release];
}
addStmt1 = nil;
if(addStmt1 == nil)
{
const char *sql ="insert into actions(action_title,action_date,dificulty_level,subid,flag,needle_num,display_date,event) Values(?,?,?,?,?,?,?,?)";
if(sqlite3_prepare_v2(database1, sql, -1, &addStmt1, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database1));
}
sqlite3_bind_text(addStmt1, 1, [appDelegate.Name UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStmt1, 2, [appDelegate.timestamp1 UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_double(addStmt1, 3, appDelegate.dif_lev);
sqlite3_bind_int(addStmt1,4,(int)appDelegate.Id);
sqlite3_bind_int(addStmt1,5,flag1);
sqlite3_bind_int(addStmt1,6,(int)appDelegate.needle_num);
sqlite3_bind_text(addStmt1, 7, [appDelegate.display_date UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStmt1, 8, [appDelegate.eventIdentifier UTF8String], -1, SQLITE_TRANSIENT);
if(SQLITE_DONE != sqlite3_step(addStmt1))
{
@try
{
NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database1));
}
@catch (NSException * e)
{
//NSLog(@"exeption run3");
}
}
sqlite3_reset(addStmt1);
sqlite3_finalize(addStmt1);
if( [appDelegate.display_date isEqualToString:@"empty"])
appDelegate.display_date = @"";
Where i am going wrong?
these functions run on 1 click.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
清理您的应用程序,然后按 Command+A,这将运行仪器并显示所有泄漏。
正如你所说,有 3 个泄漏,这意味着你已经按照上述步骤操作了。
现在正确阅读泄漏,您将了解哪一行发生泄漏的原因。
请检查一下。
快乐 iCoding...
Clean your application and then press Command+A which will run the instrument and it will show you all the leaks.
As you are saying that there are 3 leaks So it means you have followed the above step.
Now read the leak properly and you will get the reason for which line the leak is occured..
Kindly check out..
Happy iCoding...