objective c - Memory Leak with SubstringWithRange NSString -



objective c - Memory Leak with SubstringWithRange NSString -

running programme through leaks tool in x-code, points function main cause of memory leaks.

+ (nsmutablearray *) getcolumns:(nsstring *) devicehtml { nsmutablearray *ret = [[[nsmutablearray alloc] init] autorelease]; nsregularexpression *m = [[nsregularexpression alloc] initwithpattern:@"<td[\\w\\w\\d\\s</>]*?>[\\w\\w\\d\\s]+?</td>" options:nsregularexpressioncaseinsensitive error:nil]; nsarray *results = [m matchesinstring:devicehtml options:nsmatchingcompleted range:nsmakerange(0, [devicehtml length])]; [m release]; (nstextcheckingresult * res in results) { nsstring *cleaned = [devicehtml substringwithrange:[res range]]; int firstclose = [cleaned rangeofstring:@">"].location; int cleanedlength = [cleaned length]; nsstring *cleaned1 = [cleaned substringwithrange:nsmakerange(firstclose+1, cleanedlength-(firstclose+1))]; int closingcomment = [cleaned1 rangeofstring:@"</td"].location; nsstring *cleaned2 = [cleaned1 substringwithrange:nsmakerange(0, closingcomment)]; nsstring *cleaned3 = [cleaned2 stringbytrimmingcharactersinset:[nscharacterset whitespaceandnewlinecharacterset]]; [ret addobject:cleaned3]; } homecoming ret; }

specifically line,

nsstring *cleaned2 = [cleaned1 substringwithrange:nsmakerange(0, closingcomment)];

i'm not sure memory management nscfstrings , convenience methods i'm little stuck, can give me few pointers?

thanks

first, method should not getcolumns: but, say, columnsfordevice:. get* prefix has specific meaning in cocoa , isn't it.

secondly, leaks instrument shows leak allocated, not where leak may happening.

if returned array over-retained elsewhere, source of leak.

objective-c ios memory-management memory-leaks nsstring

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -