2010-12-05 7 views
0

私はmemomryリークの問題があります。多分誰かが私を助けることができます。 私はplistのためNSMutable配列をロードし、私はM.FileのviewDidLoadでNSMutableArrayとNSDictionaryのメモリリーク

@interface Bestellung : UIViewController <UITableViewDelegate, UITableViewDelegate> { 

NSMutableArray *bestellteVorspeisen; 
NSMutableArray *bestellteVorspeisenPreis; 
NSMutableArray *bestellteVorspeisenDetails; 
NSMutableArray *bestellteVorspeisenBild; 
NSMutableArray *bestellteVorspeisenNummer; 

NSMutableArray *bestellListe; 


IBOutlet UITableView *myTable; 


} 
@property (nonatomic, retain) NSMutableArray *bestellListe; 

@property (nonatomic,retain) NSMutableArray *bestellteVorspeisen; 
@property (nonatomic,retain) NSMutableArray *bestellteVorspeisenPreis; 
@property (nonatomic,retain) NSMutableArray *bestellteVorspeisenDetails; 
@property (nonatomic,retain) NSMutableArray *bestellteVorspeisenBild; 
@property (nonatomic,retain) NSMutableArray *bestellteVorspeisenNummer; 

@end 

を宣言TablevViewにh.Fileで

をいくつかの要素を示して、私はbestellListe

でPLISTをロードしようその後
NSFileManager *fileManager = [NSFileManager defaultManager]; 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"Bestellung.plist"]; 
    success = [fileManager fileExistsAtPath:filePath]; 
    if (!success) 
{  
    NSString *path = [[NSBundle mainBundle] pathForResource:@"Bestellung" ofType:@"plist"]; 
     success = [fileManager copyItemAtPath:path toPath:filePath error:&error]; 
    } 
    self.bestellListe = [[NSMutableArray alloc] initWithContentsOfFile:filePath]; 

私はMutableArray

bestellteVorspeisen  = [[NSMutableArray alloc] initWithCapacity:1]; 
bestellteVorspeisenPreis  = [[NSMutableArray alloc] initWithCapacity:1]; 
bestellteVorspeisenDetails = [[NSMutableArray alloc] initWithCapacity:1]; 
bestellteVorspeisenBild  = [[NSMutableArray alloc] initWithCapacity:1]; 
bestellteVorspeisenNummer = [[NSMutableArray alloc] initWithCapacity:1]; 

生成しますその後私は、私は、これはここで

self.bestellListe = [[NSMutableArray alloc] initWithContentsOfFile:filePath]; 

bestellteVorspeisen  = [[NSMutableArray alloc] initWithCapacity:1]; 
bestellteVorspeisenPreis  = [[NSMutableArray alloc] initWithCapacity:1]; 
bestellteVorspeisenDetails = [[NSMutableArray alloc] initWithCapacity:1]; 
bestellteVorspeisenBild  = [[NSMutableArray alloc] initWithCapacity:1]; 
bestellteVorspeisenNummer = [[NSMutableArray alloc] initWithCapacity:1]; 

でmemoryleaksイストのdealloc

- (void)dealloc { 

NSLog(@"Bestellung dealloziert"); 

[bestellteVorspeisen   release]; 
[bestellteVorspeisenPreis  release]; 
[bestellteVorspeisenDetails  release]; 
[bestellteVorspeisenBild  release]; 
[bestellteVorspeisenNummer  release]; 

[bestellListe     release]; 
[myTable      release]; 

[super dealloc]; 

は、誰かが私にいくつかの助けを与えることができます原因bestellListe

for (NSDictionary *bestellDict in bestellListe) 
    { if ([[bestellDict objectForKey:@"Tisch"] isEqualToString: 
[NSString stringWithFormat:@"%i",TischNummer]]) 
     {if ([[bestellDict objectForKey: kBestellungKategorieString] isEqualToString: @"Vorspeise"]) 
      [bestellteVorspeisen   addObject: [bestellDict objectForKey:kBestellungNameString]]; 
       [bestellteVorspeisenPreis  addObject: [bestellDict objectForKey:kBestellungPreisString]]; 
       [bestellteVorspeisenDetails  addObject: [bestellDict objectForKey:kBestellungDetailString]]; 
       [bestellteVorspeisenBild  addObject: [bestellDict objectForKey:kBestellungBildString]]; 
       [bestellteVorspeisenNummer  addObject: [bestellDict objectForKey:kBestellungNummer]]; 
} // if 
} // if 
} // for 

からそれらを埋めますそれで本当に新しい。

+0

すべてのコードを編集して、書式設定されたコードブロック、bitteに入れることができます。 –

答えて

5

あなたの財産を合成する方法自動的に受信保持するオブジェクト:だから

@property (nonatomic, retain) NSMutableArray *bestellListe; 

あなたは:

self.bestellListe = [[NSMutableArray alloc] initWithContentsOfFile:filePath]; 

あなたbestellListeが2の保持カウント(ALLOC +プロパティから保持)を持っています。あなたのdeallocで

あなたは一度だけそれを解放:

[bestellListe release]; 

を簡単な解決策は、それを作成するときのような自動解放初期化子で、一度だけ、それを保持するようだ:

self.bestellListe = [NSMutableArray arrayWithContentsOfFile:filePath]; 

これが役立つことを願って

+0

ありがとう、それは問題を解決しました。 – user3449120

関連する問題