开发者

I have seen serious leaks in 3 functions and i call these functions again and again

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 (NSEx开发者_运维百科ception * 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.


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜