views:

8

answers:

0

hi iam currently working in simple app in which i sends request in friends and call one timer background loop to access my friend response using web services . my application work good but after 10 or 15 minute my application will crash due to some problem . my code for all loop and connection are follows // NSMutableData *webData; NSXMLParser *xmlParser; NSMutableString *xmlParsingResult; NSTimer *timer; //==================== -(IBAction)mychat::(id)sender { //req all info of calling NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:req delegate:self]; if (conn) { webData = [[NSMutableData data] retain]; } }

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { [webData setLength: 0]; } -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { [webData appendData:data];
} -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { [connection release]; [webData release]; } -(void)connectionDidFinishLoading:(NSURLConnection *)connection { xmlParser = [[NSXMLParser alloc] initWithData: webData]; [xmlParser setDelegate: self]; [xmlParser setShouldResolveExternalEntities: YES]; [xmlParser parse];
[xmlParser release]; [connection release]; [webData release]; }

-(void)parser:(NSXMLParser *)xmlparser didStartElement:(NSString *)elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *)qName attributes: (NSDictionary *)attributeDict { if( [elementName isEqualToString:@"string"]) { if(!xmlParsingResult) { xmlParsingResult = [[NSMutableString alloc] init] ; }
}
}

-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { [xmlParsingResult appendString: string];
}

-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { if( [elementName isEqualToString:@"string"]) { if(timer!=nil) { } else {
NSLog(@"timer start:"); NSAutoreleasePool timerNSPool = [[NSAutoreleasePool alloc] init]; timer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(Refresh:) userInfo:nil repeats: YES]; NSRunLoop runLoop = [NSRunLoop currentRunLoop]; [runLoop run]; [timerNSPool release]; } xmlParsingResult=nil; [xmlParsingResult release]; } }
-(void)Refresh:(NSTimer *)TimeVal { // call another web services B // if B fail or error occur then timer release and nil } //==================================================================================================================