2011-05-23 67 views
-1

我一次又一次地使用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 = @""; 

我去哪裏錯了?這些功能在1次點擊上運行。

回答

0

清理您的應用程序,然後按Command + A將運行儀器,它會顯示所有泄漏。

正如你所說有3個泄漏所以這意味着你已經按照上述步驟。

現在能夠正確地閱讀泄漏,你會得到其中一線泄漏發生的原因..

請看看..

快樂iCoding ...

+0

這是一個答案? – Krishnabhadra 2011-05-23 12:21:43

+1

它的答案 – 2011-05-23 12:27:17

相關問題