я работаю на рыболовном приложение в эти дни, и я получаю проблему утечки памятиУтечка памяти, связанных с
-(void)requestFinished:(ASIFormDataRequest *) request {
if(hud != nil){
[hud show:NO];
[hud release];
hud = nil;
}
isLoading = NO;
self.responseText = [request responseString];
[self parseXml]; //I am getting leak here
if ([self.responseText hasPrefix:@"<result>"]) {
UIAlertView *info = [[[UIAlertView alloc] initWithTitle:@" " message:@"Limited Internet access, please find a stronger signal in the area" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]autorelease];
[info show];
}
if (!isRefreshButtonClicked) {
[UIAccelerometer sharedAccelerometer].delegate = self;
[NSThread detachNewThreadSelector:@selector(parseXml) toTarget:self withObject:nil];
} }
Это моя функция ...
-(void) parseXml
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
_fishes = [[fishes parseXml:self.responseText] retain];
[self performSelectorOnMainThread:@selector(parseXmlDone) withObject:nil waitUntilDone:YES];
[pool release];
Здесь _fishes массив, который получает значение от функции возврата типа массива ..... и вот эта функция ...
+(NSMutableArray *)parseXml:(NSString *)xmlString {
//xmlString = [xmlString stringByReplacingOccurrencesOfString:@"&" withString:@""];
const char *cString = [xmlString UTF8String];
NSMutableArray *fishes = [NSMutableArray array];
NSData *xmlData = [NSData dataWithBytes:cString length:strlen(cString)];
NSError *error;
GDataXMLDocument *doc = [[GDataXMLDocument alloc]initWithData:xmlData options:0 error:&error];
if (doc == nil) { return nil; }
//parseXml
NSArray *_fishes = [doc.rootElement elementsForName:@"fishery"];
for (GDataXMLElement *_fish in _fishes) {
NSMutableDictionary *fish = [NSMutableDictionary dictionary];
NSArray *ids = [_fish elementsForName:@"id"];
if ([ids count]>0) {
GDataXMLElement *firstId = (GDataXMLElement *)[ids objectAtIndex:0];
[fish setValue:firstId.stringValue forKey:@"id"];
} else continue;
NSArray *names = [_fish elementsForName:@"name"];
if ([names count]>0) {
GDataXMLElement *firstName = (GDataXMLElement *)[names objectAtIndex:0];
[fish setValue:firstName.stringValue forKey:@"name"];...........
........
else continue;
NSArray *distances = [_fish elementsForName:@"distance"];
if ([distances count]>0) {
GDataXMLElement *distance = (GDataXMLElement *)[distances objectAtIndex:0];
[fish setValue:distance.stringValue forKey:@"distance"];
}else continue;
[fishes addObject:fish];
}
[doc release];
return fishes;
}
@end
Я надеюсь, что вы, ребята, поймете и моя проблема ... Thanx
В requestFinished: вы автоматически освобождаете alertview, а также вызываете метод release на нем. Я думаю, что это вызовет проблему – Robin
@robin i отредактировал мой вопрос ...... и получил ту же проблему – Sudhanshu
как вы узнали, что вы получаете утечку памяти? – Robin