Re: Optimizing a loop
Re: Optimizing a loop
- Subject: Re: Optimizing a loop
- From: Greg Guerin <email@hidden>
- Date: Tue, 19 Jul 2011 09:47:21 -0700
Eric E. Dolecki wrote:
//Get the very best match there is to be found for
song.
if(match < currentFoundValue){
currentFoundValue = match;
test = [songsDictionary objectForKey:thisSong];
dis = [NSArray arrayWithObject:test];
collection = [[MPMediaItemCollection alloc]
initWithItems:dis];
}
}
You never release the 'collection' variable in the surrounding 'for'
loop, so if there happens to be more than one candidate match during
the search, you'll leak all but one MPMediaItemCollection object.
Personally, I'd just defer the array-making (dis) and collection-
making (collection) until after the 'for' loop finds the closest
match. Only do those things in the loop that are relevant to the
loop: which is finding the closest matching MPMediaItem. If it's not
relevant to that search, defer it until after the closest match is
found.
BTW, if you haven't profiled your code, you should do that first,
before making any changes at all. You haven't posted any evidence
that the fuzzy matching of your StringDistance class is the cause of
the performance problem. It could just as easily be the making of
dis and collection that's the problem. Or it could be that the
problem is better solved by improving the code of StringDistance
(which you haven't posted). There's no way of knowing without
profiling first.
-- GG
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden