1

私はこの問題を2日間続けていましたが、私が何をしていても、漏れた文字列を止めることはできません。XML解析クラス再呼び出し時に文字列がリークする

クラスはXMLパーザ(TouchXMLを使用)で、アプリケーションのライフタイム全体にわたって繰り返し実行されるように設計されています。それが初めて実行されたとき、漏れはなく、すべてが完全にきれいになります。 2回目の走行では、ほとんど常に弦がどこにあるかが漏れ始めます。

インスツルメンツからいくつかの画像:

http://www.producerstudio.net/1.png

http://www.producerstudio.net/2.png

の.h

#import <Foundation/Foundation.h> 
#import "TouchXML.h" 

@protocol RSSParsingComplete 
-(void)parsingFinished; 
@end 

@interface RSS : NSObject<NSXMLParserDelegate>{ 
    NSArray *rssURLArray; 
    NSMutableData *xmlData;  
    NSMutableArray *articles; 
    NSMutableArray *arrayOfArticles; 






    int numberOfFeeds; 
    NSDateFormatter *inputFormatter; 
    NSDateFormatter *outputFormatter; 

    id<RSSParsingComplete> delegate; 
} 

@property (nonatomic, retain) NSArray *rssURLArray; 
@property (nonatomic, retain) NSMutableData *xmlData; 
@property (nonatomic, retain) id<RSSParsingComplete> delegate; 

@property (nonatomic, retain) NSMutableArray *articles; 
@property (nonatomic, retain) NSMutableArray *arrayOfArticles; 

@property (nonatomic, retain) NSDateFormatter *inputFormatter; 
@property (nonatomic, retain) NSDateFormatter *outputFormatter; 

-(id)initWithRSSArray:(NSArray *)inputURLArray; 
-(void)connect; 
-(NSArray *)feedArticles; 

@end 

.M

#import "RSS.h" 

@implementation RSS 
@synthesize xmlData, rssURLArray, articles, arrayOfArticles, delegate, inputFormatter, outputFormatter; 

-(void)connect{  
    self.xmlData = [[[NSMutableData alloc] init] autorelease]; 
    NSURL *rssURL = [[NSURL alloc] initWithString:[self.rssURLArray objectAtIndex:numberOfFeeds-1]]; 
    NSURLConnection *urlConnection = [[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithURL:rssURL] delegate:self]; 
    [urlConnection release]; 
    [rssURL release]; 
} 

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ 
    [self.xmlData setLength:0]; 
} 

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ 
    [self.xmlData appendData:data]; 
} 

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{ 
    [xmlData release]; 
    [connection release]; 
} 

-(void)connectionDidFinishLoading:(NSURLConnection *)connection{ 
    CXMLDocument *xmlDoc = [[[CXMLDocument alloc] initWithData:xmlData options:0 error:nil] autorelease]; 
    self.articles = [[[NSMutableArray alloc] init] autorelease]; 

    self.inputFormatter = [[[NSDateFormatter alloc] init] autorelease]; 
    self.outputFormatter = [[[NSDateFormatter alloc] init] autorelease]; 
    [self.inputFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss zzz"]; 
    [self.inputFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]]; 
    [self.inputFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]]; 
    [self.outputFormatter setDateFormat:@"dd.MM.yyyy HH:mm:ss"]; 
    [self.outputFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]]; 
    [self.outputFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]]; 

    NSArray *itemNodes = [xmlDoc nodesForXPath:@"//item" error:nil];  
    for(CXMLElement *node in itemNodes){ 
     NSMutableDictionary *article = [[NSMutableDictionary alloc] init]; 
     for(int counter = 0; counter < [node childCount]; counter++){ 
      if([[[node childAtIndex:counter] name] isEqualToString:@"title"]){ 
       [article setObject:[[node childAtIndex:counter] stringValue] forKey:@"title"]; 
      } 
      if([[[node childAtIndex:counter] name] isEqualToString:@"link"]){ 
       [article setObject:[[node childAtIndex:counter] stringValue] forKey:@"url"]; 
      } 
      if([[[node childAtIndex:counter] name] isEqualToString:@"description"]){ 
       [article setObject:[[node childAtIndex:counter] stringValue] forKey:@"description"]; 
      } 
      if([[[node childAtIndex:counter] name] isEqualToString:@"pubDate"]){ 
       NSDate *tempDate = [self.inputFormatter dateFromString:[[node childAtIndex:counter] stringValue]]; 
       [article setObject:[self.outputFormatter stringFromDate:tempDate] forKey:@"name"]; 
      } 
     } 
     [self.articles addObject:article]; 
     [article release]; 
    } 

    NSArray *feedTitleNode = [xmlDoc nodesForXPath:@"//title" error:nil]; 
    NSString *feedTitle = [[NSString alloc] initWithString:[[[feedTitleNode objectAtIndex:0] childAtIndex:0] stringValue]]; 
    [self.articles addObject:feedTitle]; 
    [feedTitle release]; 

    [self.arrayOfArticles addObject:[articles copy]]; 
    [self.articles removeAllObjects]; 
    [inputFormatter release]; 
    [outputFormatter release]; 
    numberOfFeeds--; 
    if(numberOfFeeds > 0){ 
     [self connect]; 
    }else{ 
     [delegate parsingFinished]; 
    } 
} 



-(NSArray *)feedArticles{  
    NSLog(@"Array of Articles: %@", self.arrayOfArticles); 
    return self.arrayOfArticles; 
} 

-(id)initWithRSSArray:(NSArray *)inputURLArray{ 
    self = [super init]; 
    if (self) {  
     self.arrayOfArticles = [[[NSMutableArray alloc] init] autorelease]; 
     self.rssURLArray = [[[NSArray alloc] initWithArray:inputURLArray] autorelease];  
     numberOfFeeds = [self.rssURLArray count];   
     [self connect]; 
    } 
    return self; 
} 

-(void)dealloc{ 
    [rssURLArray release]; 
    [xmlData release]; 
    [articles release];  
    [arrayOfArticles release]; 
    [super dealloc]; 
} 

- (id)init 
{ 
    self = [super init]; 
    return self; 
} 

@end 

私は、漏れを解決するために私が考えることができるすべてを行った。私はApple Memory ManagementのガイドとiPhoneDevSDKの優れたガイドを読んだので、元々は漏れの90%を減らすことができました。たぶん私はこれをあまりにも長く見てきたのかもしれません。

私はそれを感謝します!

答えて

0

まず、代理人を保持する必要がありますか?私はあなたがなぜインスタンス変数としてそれを必要としているのかわかりません。しかし、それは保持されているので(あなたはそれを解放していないように見える)、あなたのRSSオブジェクトは自身への循環参照を保持し、リリースされることはありません。

第2に、日付フォーマッタをインスタンス変数に保存する必要がありますか?あなたがそれらを割り当てて、同じ方法でそれらを解放しているように見えます。それらはRSSインスタンスに保持され、決して解放されないことに注意してください。

関連する問題