memory leaks - MemoryLeaking - question -


i have function getalldata, wich returning array dictonaries.

- (nsarray *)getalldata {      nsmutablearray *result = [[nsmutablearray alloc] init];         nsarray *data = [skiresorts sortedarrayusingfunction:comparator context:null];      nsstring *currentletter = @"a";     nsmutablearray *array = [[nsmutablearray alloc] init] ;     nsmutabledictionary *dict = [[nsmutabledictionary alloc] init] ;      if ([data count] > 0) {         (skiresort *resort in data) {              if ([resort.name hasprefix:currentletter]) {                 // same letter before.                                 // add current skiresort temporary array.                 [array addobject:resort];             } else {                 // new letter.                                     // add previous header/row data dictionary.                 [dict setvalue:currentletter forkey:@"header"];                 [dict setvalue:array forkey:@"row"];                  // add dictionary final result array.                 [result addobject:dict];                  // startover ...                  [array removeallobjects];                 [dict removeallobjects];                  // prepare next letter.                 currentletter = [resort.name substringtoindex:1];                   // add current skiresort temporary array.                 [array addobject:resort];             }         }          // add previous header/row data dictionary.        [dict setvalue:currentletter forkey:@"header"];        [dict setvalue:array forkey:@"row"];          // add dictionary final result array.        [result addobject:dict];     }     [array release];         [dict release];         return [result autorelease]; } 

can see obvious memoryleaks in code? memory leak array, dict, , result ...

from code, have ask: you're aware addobject: doesn't copy object? setting values dict, adding result, removing dict leaves empty dictionary in result? think want use 'copy' method in there, make copies of array , dictionary. or, better, create dictionary when add result using 1 of class methods.

anyway, since can't see leaks in that, more whoever receives result of getalldata subsequently leaks it. if crazy reason had somewhere stray:

[[object getalldata] retain]; 

then leaks tool identify leak of array, dict , result , point getalldata method in created.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -