Problem realeasing allocated objects - objective-c

Crash occurs at [searchDict release]. If I switch order of the two latest lines it still crash on the latest line (now [searchArray release]). I'm quite new to Objective C and I guess I haven't got the alloc/release right... Help? :)
NSMutableDictionary *searchDict = [[NSMutableDictionary alloc] init];
NSMutableArray *searchArray = [[NSMutableArray alloc] init];
for(int i = 0; i < 2; i++) { // Run two times ("Favorites" and "All")
searchDict = [listOfItems objectAtIndex:i];
searchArray = [searchDict objectForKey:#"Entries"];
for (NSString *sTemp in searchArray) {
NSRange titleResultsRange = [sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (titleResultsRange.length > 0)
[listOfItemsDynamic addObject:sTemp];
}
}
[searchArray release];
[searchDict release];

You allocate space and assign it to the variables:
NSMutableDictionary *searchDict = [[NSMutableDictionary alloc] init];
NSMutableArray *searchArray = [[NSMutableArray alloc] init];
But then you assign non locally-allocated data to them:
searchDict = [listOfItems objectAtIndex:i];
searchArray = [searchDict objectForKey:#"Entries"];
So basically, you don't need to allocate and release. Instead do something like this:
NSMutableDictionary *searchDict; // Just declartion, no allocation / init
NSMutableArray *searchArray; // Just declartion, no allocation / init
for(int i = 0; i < 2; i++) { // Run two times ("Favorites" and "All")
searchDict = [listOfItems objectAtIndex:i];
searchArray = [searchDict objectForKey:#"Entries"];
for (NSString *sTemp in searchArray) {
NSRange titleResultsRange = [sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (titleResultsRange.length > 0)
[listOfItemsDynamic addObject:sTemp];
}
}
// No release needed here
If you are familiar with C, it is similar to:
char *pChar;
pChar = malloc(15); // allocate memory and assign to pChar
pChar = "Hello"; // assign new address to pChar
free(pChar); // Error here ;)

Related

Memory leak while handling Foundation Object from NSJSONSerialization

I'm struggling to fix a memory leak in a helper function I have made. The helper function takes the result of
+ (id)JSONObjectWithData:(NSData *)data options:(NSJSONReadingOptions)opt error:(NSError * _Nullable *)error
and converts all the leaf elements into NSStrings if they are NSNumbers.
Here is the method:
-(NSArray *) stringisizeObjects:(NSArray *)inputArray{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSMutableArray *mutable = [[NSMutableArray alloc] initWithCapacity:[inputArray count]];
for (int i = 0; i < [inputArray count]; i++) {
NSArray *keys = [inputArray[i] allKeys];
NSMutableDictionary *addDictionary = [[NSMutableDictionary alloc] initWithCapacity:[keys count]];
for (int j = 0; j < [keys count]; j++) {
id theObject = [[inputArray[i] objectForKey:keys[j]]autorelease];
if ([theObject isKindOfClass:[NSNumber class]]) {
[addDictionary setObject:[theObject stringValue] forKey:keys[j]];
[theObject release];
}else if ([theObject isKindOfClass:[NSString class]]){
[addDictionary setObject:[inputArray[i] objectForKey:keys[j]] forKey:keys[j]];
}
}
[mutable addObject:addDictionary];
}
NSArray *returnArray = [mutable copy];
[mutable removeAllObjects];
[mutable release];
[pool drain];
return returnArray;
}
Here is how I get the input array.
id parsedThingy = [NSJSONSerialization JSONObjectWithData:resultJSONData options:1 error:&jsonDecodeError];
Before I can pass the result to my stringisize method I must ensure that I have an NSArray of NSDictionaries with matching keys.
NSArray *resultArray = [self stringisizeObjects:parsedThingy];
The X-Code memory leaks tool has pointed me to this method as the cause of my problem.
Instruments showing leaks
As you can see I have tried wrapping things in autorelease pools, autoreleasing and releasing. I just don't see any way forward here.
This is a non ARC project that runs 24/7.
Edit: I took the advice from Droppy and tried to re-write the method using mutableCopy. The leak is still there. At this point my only work around maybe to change the source of the JSON to send only strings. :(
-(NSArray *) stringisizeObjects2:(NSArray *)inputArray{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSMutableArray *mutableArray = [inputArray mutableCopy];
for (int i = 0; i < [mutableArray count]; i++) {
NSMutableDictionary *mutableDict = [mutableArray[i] mutableCopy];
NSArray *keys = [mutableDict allKeys];
for (int j = 0; j < [keys count]; j++) {
if ([[mutableDict objectForKey:keys[j]] isKindOfClass:[NSNumber class]]) {
NSString *stringValue = [[mutableDict objectForKey:keys[j]] stringValue];
[mutableDict removeObjectForKey:keys[j]];
[mutableDict setObject:stringValue forKey:keys[j]];
}
}
mutableArray[i] = [mutableDict copy];
[mutableDict release];
}
NSArray *returnArray = [mutableArray copy];
[mutableArray release];
[pool drain];
return returnArray;
}
problem:
addDictionary called alloc but not call release or autorelease
returnArray = [mutable copy]; // did increase retainCount +1, need autorelease here
id theObject = [inputArray[i] objectForKey:keys[j]]; // not need autorelease or release for object that You not own
add NSAutoreleasePool to top an bottom here just do nothing
solution:
-(NSArray *) stringisizeObjects:(NSArray *)inputArray{
NSMutableArray *mutable = [[NSMutableArray alloc] initWithCapacity:[inputArray count]];
for (int i = 0; i < [inputArray count]; i++) {
NSArray *keys = [inputArray[i] allKeys];
NSMutableDictionary *addDictionary = [[NSMutableDictionary alloc] initWithCapacity:[keys count]];
for (int j = 0; j < [keys count]; j++) {
id theObject = [inputArray[i] objectForKey:keys[j]]; // not need autorelease
if ([theObject isKindOfClass:[NSNumber class]]) {
[addDictionary setObject:[theObject stringValue] forKey:keys[j]];
//[theObject release]; // not need release value here
}else if ([theObject isKindOfClass:[NSString class]]){
[addDictionary setObject:[inputArray[i] objectForKey:keys[j]] forKey:keys[j]];
}
}
[mutable addObject:addDictionary];
[addDictionary release]; // release after not use
}
NSArray *returnArray = [[[NSArray alloc] initWithArray:mutable] autorelease]; // auto release for return value
[mutable removeAllObjects];
[mutable release];
return returnArray;
}

Value stored to 'myKeyArray' during its initialization is never read

I get the "Value stored to 'myKeyArray' during its initialization is never read" message for the marked lines and i do not quite understand why this is happening.
- (void)createAndMigrateStatisticalDataForPlayersToV3 {
NSString *playerStatsfilePath = [self dataFilePath5];
NSString *playerDatafilePath = [self dataFilePath6];
NSArray *myKeyArray = [[NSArray alloc]init]; <<<< "Value stored to 'myKeyArray' during its initialization is never read"
NSMutableArray *theObjects = [[NSMutableArray alloc]init]; <<<< "Value stored to 'myKeyArray' during its initialization is never read"
NSFileManager *fileMgr;
fileMgr = [NSFileManager defaultManager];
if ([fileMgr fileExistsAtPath: playerDatafilePath] == YES) {
NSMutableDictionary *gameFileDict = [NSMutableDictionary dictionaryWithContentsOfFile:playerDatafilePath];
NSMutableArray *dataArray = [[NSMutableArray alloc]init];
NSMutableArray *newDataArray = [[NSMutableArray alloc]init];
myKeyArray = [gameFileDict allKeys];
int nrOfKeys = [myKeyArray count];
for (int oo = 0; oo < nrOfKeys; oo++) {
theObjects = [gameFileDict valueForKey:[myKeyArray objectAtIndex:oo]];
[dataArray addObject:[myKeyArray objectAtIndex:oo]]; // Name
[dataArray addObject:[theObjects objectAtIndex:1]]; // # of games played
[dataArray addObject:[theObjects objectAtIndex:2]]; // # correct answers
[dataArray addObject:[theObjects objectAtIndex:3]]; // # questions
[dataArray addObject:[theObjects objectAtIndex:4]]; // # of games won
[dataArray addObject:[theObjects objectAtIndex:5]]; // # of games lost
}
int dataCount = [dataArray count];
float avgNrOfQuestionsPerGame = 0;
float avgNrCorrectAnswersPerGame = 0;
float nrOfQuestions = 0;
float nrOfCorrectAnswers = 0;
float nrOfGamesPerPlayer = 0;
float nrOfMatchesWonPerPlayer = 0;
float nrOfMatchesLostPerPlayer = 0;
for (int oo = 0; oo < dataCount; oo = oo + 6) {
nrOfGamesPerPlayer = [[dataArray objectAtIndex:oo+1]floatValue];
nrOfCorrectAnswers = [[dataArray objectAtIndex:oo+2]floatValue];
nrOfQuestions = [[dataArray objectAtIndex:oo+3]floatValue];
nrOfMatchesWonPerPlayer = [[dataArray objectAtIndex:oo+4]floatValue];
nrOfMatchesLostPerPlayer = [[dataArray objectAtIndex:oo+5]floatValue];
// nrOfGamesPerPlayer = nrOfMatchesLostPerPlayer + nrOfMatchesLostPerPlayer;
avgNrOfQuestionsPerGame = nrOfQuestions / nrOfGamesPerPlayer;
avgNrCorrectAnswersPerGame = nrOfCorrectAnswers / nrOfGamesPerPlayer;
for (int ff = 0; ff < nrOfGamesPerPlayer; ff++) {
[newDataArray addObject:[dataArray objectAtIndex:oo]]; //PlayerName
[newDataArray addObject:[self get_the_Date]]; //set todays date
[newDataArray addObject:[NSNumber numberWithInt:avgNrOfQuestionsPerGame]];
[newDataArray addObject:[NSNumber numberWithInt:avgNrCorrectAnswersPerGame]];
}
}
[newDataArray writeToFile:playerStatsfilePath atomically: TRUE];
}
I would take this line out, You shouldn't need to initialize it.
//NSArray *myKeyArray = [[NSArray alloc]init];
Change this to
NSArray *myKeyArray;
You only need to allocate it if it is mutable.
You're reassigning both myKeyArray and theObjects after you allocated memory for them, so you have a massive memory leak.
Remove the declarations with the allocations and move the variable declaration to the line where you perform the assignment:
NSArray *myKeyArray = [gameFileDict allKeys];
The same for theObjects:
NSArray *theObjects = [gameFileDict valueForKey:[myKeyArray objectAtIndex:oo]];
Note that you don't have to declare it as NSMutableArray. You're not changing the array.

NSArray: Remove objects with duplicate properties

I have an NSMutableArray that contains a few custom objects. Two of the objects have the same properties such as title and author. I want to remove the duplicate object and leave the other.
Asset *asset;
NSMutableArray *items = [[[NSMutableArray alloc] init] autorelease];
// First
asset = [[Asset alloc] init];
asset.title = #"Developer";
asset.author = #"John Smith";
[items addObject:asset];
[asset release];
// Second
asset = [[Asset alloc] init];
asset.title = #"Writer";
asset.author = #"Steve Johnson";
[items addObject:asset];
[asset release];
// Third
asset = [[Asset alloc] init];
asset.title = #"Developer";
asset.author = #"John Smith";
[items addObject:asset];
[asset release];
Since they are NOT the same object, but only having duplicate properties, how can I remove the duplicate?
You could create a HashSet and as you loop, you could add "title+author" concatenated set to the HashSet (NSMutableSet). As you arrive at each item, if the HashSet contains your key, either remove it or don't copy (either deleting or creating a copy without duplicates).
That makes it order n (1 loop)
Here's the NSMutableSet class:
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSMutableSet_Class/Reference/NSMutableSet.html#//apple_ref/occ/cl/NSMutableSet
EDIT with code:
The meat of the code is the one loop.
void print(NSMutableArray *assets)
{
for (Asset *asset in assets)
{
NSLog(#"%#/%#", [asset title], [asset author]);
}
}
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
//
// Create the initial data set
//
Asset *asset;
NSMutableArray *items = [[[NSMutableArray alloc] init] autorelease];
// First
asset = [[Asset alloc] init];
asset.title = #"Developer";
asset.author = #"John Smith";
[items addObject:asset];
[asset release];
// Second
asset = [[Asset alloc] init];
asset.title = #"Writer";
asset.author = #"Steve Johnson";
[items addObject:asset];
[asset release];
// Third
asset = [[Asset alloc] init];
asset.title = #"Developer";
asset.author = #"John Smith";
[items addObject:asset];
[asset release];
NSLog(#"****Original****");
print(items);
//
// filter the data set in one pass
//
NSMutableSet *lookup = [[NSMutableSet alloc] init];
for (int index = 0; index < [items count]; index++)
{
Asset *curr = [items objectAtIndex:index];
NSString *identifier = [NSString stringWithFormat:#"%#/%#", [curr title], [curr author]];
// this is very fast constant time lookup in a hash table
if ([lookup containsObject:identifier])
{
NSLog(#"item already exists. removing: %# at index %d", identifier, index);
[items removeObjectAtIndex:index];
}
else
{
NSLog(#"distinct item. keeping %# at index %d", identifier, index);
[lookup addObject:identifier];
}
}
NSLog(#"****Filtered****");
print(items);
[pool drain];
return 0;
}
Here's the output:
Craplet[11991:707] ****Original****
Craplet[11991:707] Developer/John Smith
Craplet[11991:707] Writer/Steve Johnson
Craplet[11991:707] Developer/John Smith
Craplet[11991:707] distinct item. keeping Developer/John Smith at index 0
Craplet[11991:707] distinct item. keeping Writer/Steve Johnson at index 1
Craplet[11991:707] item already exists. removing: Developer/John Smith at index 2
Craplet[11991:707] ****Filtered****
Craplet[11991:707] Developer/John Smith
Craplet[11991:707] Writer/Steve Johnson
You can use the uniqueness of an NSSet to get distinct items from your original array. If you have the source code for Assest you will need to override the hash and isEqual: method on the Asset class.
#interface Asset : NSObject
#property(copy) NSString *title, *author;
#end
#implementation Asset
#synthesize title, author;
-(NSUInteger)hash
{
NSUInteger prime = 31;
NSUInteger result = 1;
result = prime * result + [self.title hash];
result = prime * result + [self.author hash];
return result;
}
-(BOOL)isEqual:(id)object
{
return [self.title isEqualToString:[object title]] &&
[self.author isEqualToString:[object author]];
}
- (void)dealloc {
[title release];
[author release];
[super dealloc];
}
#end
Then to implement:
Asset *asset;
NSMutableArray *items = [[[NSMutableArray alloc] init] autorelease];
// First
asset = [[Asset alloc] init];
asset.title = #"Developer";
asset.author = #"John Smith";
[items addObject:asset];
[asset release];
// Second
asset = [[Asset alloc] init];
asset.title = #"Writer";
asset.author = #"Steve Johnson";
[items addObject:asset];
[asset release];
// Third
asset = [[Asset alloc] init];
asset.title = #"Developer";
asset.author = #"John Smith";
[items addObject:asset];
[asset release];
NSLog(#"Items: %#", items);
NSSet *distinctItems = [NSSet setWithArray:items];
NSLog(#"Distinct: %#", distinctItems);
And if you need an array at the end you can just call [distinctItems allObjects]
First, I'd override the isEqual: method for Asset like this:
-(BOOL)isEqual:(Asset *)otherAsset {
return [self.title isEqual:otherAsset.title] && [self.author isEqual:otherAsset.author];
}
Then, if you want to avoid placing duplicates in the array in the first place:
NSUInteger idx = [items indexOfObject:asset]; // tests objects for equality using isEqual:
if (idx == NSNotFound) [items addObject:asset];
If the array already contains duplicates, then any algorithm that finds them has a run time already worse than linear, but I think creating a new array and only adding unique elements like above is the best algorithm. Something like this:
NSMutableArray *itemsWithUniqueElements = [NSMutableArray arrayWithCapacity:[items count]];
for (Asset *anAsset in items) {
if ([items indexOfObject:anAsset] == NSNotFound)
[itemsWithUniqueElements addObject:anAsset];
}
[items release];
items = [itemsWithUniqueElements retain];
In the worst case scenario (all elements are already unique) the number of iterations is:
1 + 2 + 3 + ... + n = n * (n+1) / 2
Which is still O(n^2) but is slightly better than #Justin Meiners' algorithm. No offense! :)
This is one way you could do it
:
NSMutableArray* toRemove = [NSMutableArray array];
for (Asset* asset1 in items)
{
for (Asset* asset2 in items)
{
if (asset1 != asset2)
{
if ([asset1.title isEqualToString:asset2.title] && [asset1.author isEqualToString:asset2.author])
{
[toRemove addObject:asset2];
}
}
}
}
for (Asset* deleted in toRemove)
{
[items removeObject:toRemove];
}
If you'd like your custom NSObject subclasses to be considered equal when their names are equal you may implement isEqual: and hash. This will allow you to add of the objects to an NSSet/NSMutableSet (a set of distinct objects).
You may then easily create a sorted NSArray by using NSSet's sortedArrayUsingDescriptors:method.
MikeAsh wrote a pretty solid piece about implementing custom equality: Friday Q&A 2010-06-18: Implementing Equality and Hashing

releasing a NSMutableArray is causing EXC_BAD_ACCESS error

so when i try to run the following code, i end up with a EXC_BAD_ACCESS error. it happens when i try to release a NSMutableArray retrievedAnalysisDataList. the array is a list of retrievedAnalysisData objects. if i try to either release the data list or if i set up the init with an autorelease, i get the same result. i'm kinda guessing it has something to do with the sorting section of the code since i don't have this issue with the retrievedAnalysisIDarray.
any ideas?
if (tempDict != NULL)
{
NSMutableArray *retrievedAnalysisDataList = [[NSMutableArray alloc] init];
NSMutableArray *retrievedAnalysisIDarray = [[NSMutableArray alloc] init];
for (id key in tempDict)
{
retrievedAnalysisData = [[RetrievedAnalysisData alloc] init];
retrievedAnalysisData.createDate = [[tempDict objectForKey:key] objectForKey:#"createdate"];
retrievedAnalysisData.ID = [[tempDict objectForKey:key] objectForKey:#"id"];
retrievedAnalysisData.mode = [[tempDict objectForKey:key] objectForKey:#"mode"];
retrievedAnalysisData.name = [[tempDict objectForKey:key] objectForKey:#"name"];
retrievedAnalysisData.numZones = [[tempDict objectForKey:key] objectForKey:#"numzones"];
retrievedAnalysisData.srcImg = [[tempDict objectForKey:key] objectForKey:#"srcimg"];
retrievedAnalysisData.type = [[tempDict objectForKey:key] objectForKey:#"type"];
//NSLog(#"\n createDate: %# \n id: %# \n mode: %# \n name: %# \n numzone: %# \n srcimg: %# \n type: %#", retrievedAnalysisData.createDate, retrievedAnalysisData.ID, retrievedAnalysisData.mode, retrievedAnalysisData.name, retrievedAnalysisData.numZones, retrievedAnalysisData.srcImg, retrievedAnalysisData.type);
[retrievedAnalysisDataList addObject:retrievedAnalysisData];
[retrievedAnalysisData release];
}
NSSortDescriptor *sortDescriptor;
sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:#"createDate" ascending:YES] autorelease];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
NSArray *sortedRetrievedAnalysisDataList;
sortedRetrievedAnalysisDataList = [retrievedAnalysisDataList sortedArrayUsingDescriptors:sortDescriptors];
int count = [sortedRetrievedAnalysisDataList count];
for (int i = 0; i < count; i++) {
retrievedAnalysisData = [[RetrievedAnalysisData alloc] init];
retrievedAnalysisData = [sortedRetrievedAnalysisDataList objectAtIndex:i];
[retrievedAnalysisIDarray addObject:retrievedAnalysisData.ID];
[retrievedAnalysisData release];
}
dataCenter.sortedRetrievedAnalysisDataList = sortedRetrievedAnalysisDataList;
dataCenter.retrievedAnalysisIDarray = retrievedAnalysisIDarray;
[retrievedAnalysisIDarray release];
[retrievedAnalysisDataList release];
dataCenter.isRetrieve = [NSNumber numberWithInt:1];
[activityIndicator stopAnimating];
[picker reloadAllComponents];
picker.hidden = FALSE;
pickerToolBar.hidden = FALSE;
toolBar.hidden = TRUE;
innerCircle.hidden = TRUE;
outerCircle.hidden = TRUE;
trackLabel.hidden = TRUE;
displayGPSLabel.hidden = TRUE;
}
Your problem lies in this section of code:
retrievedAnalysisData = [[RetrievedAnalysisData alloc] init];
retrievedAnalysisData = [sortedRetrievedAnalysisDataList objectAtIndex:i];
[retrievedAnalysisIDarray addObject:retrievedAnalysisData.ID];
[retrievedAnalysisData release];
The first line allocates a new RetrievedAnalysisData, but then the second throws that away (leaking it) and places an object fetched from the array in the retrievedAnalysisData variable instead. You don't own this object fetched from the array, and you don't take ownership by calling retain. So the release on the fourth line is incorrect, releasing an object that you do not own.
Then when you release your NSMutableArray, it tries to release the object again and you get a crash because the object is already released.
To fix it, get rid of the useless first line, and also get rid of the incorrect release.
Without knowing the memory management of all your properties, it’s hard to see exactly what’s going on. But take a look here:
for (int i = 0; i < count; i++) {
retrievedAnalysisData = [[RetrievedAnalysisData alloc] init];
retrievedAnalysisData = [sortedRetrievedAnalysisDataList objectAtIndex:i];
[retrievedAnalysisIDarray addObject:retrievedAnalysisData.ID];
[retrievedAnalysisData release];
}
You call -release on an autoreleased object (retrievedAnalysisData). Try this instead:
for (int i = 0; i < count; i++) {
retrievedAnalysisData = [sortedRetrievedAnalysisDataList objectAtIndex:i];
[retrievedAnalysisIDarray addObject:retrievedAnalysisData.ID];
}

potential leak problems

when I build and analize my application , am getting potential leak near the code [array1 release]...why its happening there..?thanks in advance
- (void) touchOnFeaturedCatalog
{
searchId == 2;
//featuredCatalogName = #"23064_Leeds2010";
//NSString *response = [ZoomCatalogAppDelegate getResponseFromServer:[NSString stringWithFormat:#"http://www.zoomcatalog.com/iphone/iphone.php?catalog=%#&iphone=Yes&pdf=No", featuredCatalogName]];
NSString *response = [ZoomCatalogAppDelegate getResponseFromServer:#"http://www.zoomcatalog.com/iphone/supplier.php"];
//NSString *response = [ZoomCatalogAppDelegate getResponseFromServer:#"http://test.atvescape.com/articles.php"];
//NSLog(#"Response = %#", response);
NSArray *array = [response componentsSeparatedByString:#"##"];
[array retain];
for(int i = 0; i < array.count; i++)
{
NSLog(#"Trying outer loop.... %d, %#, %#", i, [array objectAtIndex:i], featuredCatalogName);
NSArray *array4 = [featuredCatalogName componentsSeparatedByString:[array objectAtIndex:i]];
if(array4.count > 1)
{
response = [ZoomCatalogAppDelegate getResponseFromServer:[NSString stringWithFormat:#"http://www.zoomcatalog.com/iphone/catalog_search.php?tid2=%#&iphone=yes", [array objectAtIndex:i]]];
NSArray *array3= [response componentsSeparatedByString:#"<br>"];
//baseURL = [NSString stringWithFormat:#"%#", [array3 objectAtIndex:0]];
global_ContentString = [NSString stringWithFormat:#"%#", [array3 objectAtIndex:2]];//(searchId == 1 ? [array objectAtIndex:2] : ([array objectAtIndex: isLineNameSearch ? 2 : 1]))];
[global_ContentString retain];
// NSLog(#"baseURL = %#", global_ContentString);
NSArray *array1 = [global_ContentString componentsSeparatedByString:#"###"];
for(int j = 0; j < array1.count; j++)
{
NSArray *array2 = [[array1 objectAtIndex:j] componentsSeparatedByString:#"##"];
NSString *str = [NSString stringWithFormat:#"%#", [array2 objectAtIndex:0]];
str = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if ([str caseInsensitiveCompare:featuredCatalogName] == NSOrderedSame)
{
global_ContentString = [ZoomCatalogAppDelegate getResponseFromServer:[NSString stringWithFormat:#"http://www.zoomcatalog.com/iphone/iphone.php?catalog=%#&iphone=Yes&pdf=No", [array2 objectAtIndex:5]]];
baseURL = [NSString stringWithFormat:#"%#", [[global_ContentString componentsSeparatedByString:#"<br>"] objectAtIndex:0]];
//global_ContentString = [NSString stringWithFormat:#"%#", [[global_ContentString componentsSeparatedByString:#"<br>"] objectAtIndex:1]];
[global_ContentString retain];
[global_MainPageController presentModalViewController:global_FullPageController animated:YES];
//NSLog(#"$$$$$$$$$$$$$$$$$$$$$$ Catalog id = %# $$$$$$$$$$$$$$$$$$$$$$$$$$", [array2 objectAtIndex:5]);
//[array1 release];memory leak
return;
}
// NSLog(#"Trying inner loop.... %d, %#, %#", j, str, featuredCatalogName);
}
}
// if([[array objectAtIndex:i] com
}
[array release];
return;
}
sorry for all..
If you are only using an object locally (within the method in which it is created) you can autorelease it. Objects that are created or returned by convenience methods available until the end of the function call. Unless you need the objects elsewhere, I suggest ditching the retain calls. The rule of thumb is that whenever you call alloc, new, retain, or copy you mist release the object. However, if you use a convenience method, The returned object is autogenerate for you.
It seems that you call [global_ContentString retain]; but then fail to call a corresponding release.