Note that there are some explanatory texts on larger screens.

plurals
  1. POMemory Leak from NSMutableArray and NSDictionary
    text
    copied!<p>I have a memomry leak problem, maybe somebody can help me. I try to load an NSMutable array for a pList and show some elements in a TablevView</p> <p>In the h.File I declare</p> <pre><code>@interface Bestellung : UIViewController &lt;UITableViewDelegate, UITableViewDelegate&gt; { 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 </code></pre> <p>In the M.File viewDidLoad I load the pList in bestellListe</p> <pre><code>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:&amp;error]; } self.bestellListe = [[NSMutableArray alloc] initWithContentsOfFile:filePath]; </code></pre> <p>Then I generate the MutableArray</p> <pre><code>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]; </code></pre> <p>Afterwards I fill them from bestellListe</p> <pre><code>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 </code></pre> <p>This causes memoryleaks at </p> <pre><code>self.bestellListe = [[NSMutableArray alloc] initWithContentsOfFile:filePath]; </code></pre> <p>and</p> <pre><code>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]; </code></pre> <p>Here ist dealloc</p> <pre><code>- (void)dealloc { NSLog(@"Bestellung dealloziert"); [bestellteVorspeisen release]; [bestellteVorspeisenPreis release]; [bestellteVorspeisenDetails release]; [bestellteVorspeisenBild release]; [bestellteVorspeisenNummer release]; [bestellListe release]; [myTable release]; [super dealloc]; </code></pre> <p>Can somebody give me some help, I'm really new in that.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload