0
我正在釣魚的應用程序,這些天,我收到了內存泄漏問題內存泄漏相關
-(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
我希望能跟大家會underst和我的問題...感謝名單
In requestFinished:你自動發佈了alertview,並且也調用了release方法。我認爲,這將導致一個問題 – Robin 2011-01-11 11:22:57