deallocated memory in tableview: message sent to deallocated instance

Posted by Kirn on Stack Overflow See other posts from Stack Overflow or by Kirn
Published on 2010-05-26T18:40:03Z Indexed on 2010/05/26 19:01 UTC
Read the original article Hit count: 260

I tried looking up other issues but couldn't find anything to match so here goes:

I'm trying to display text in the table view so I use this bit of code:

// StockData is an object I created and it pulls information from Yahoo APIs based on 
//  a stock ticker stored in NSString *heading

    NSArray* tickerValues = [heading componentsSeparatedByString:@" "];
StockData *chosenStock = [[StockData alloc] initWithContents:[tickerValues objectAtIndex:0]];
[chosenStock getData];

// Set up the cell...
NSDictionary *tempDict = [chosenStock values];
NSArray *tempArr = [tempDict allValues];
cell.textLabel.text = [tempArr objectAtIndex:indexPath.row];
return cell;

This is all under cellForRowAtIndexPath

When I try to release the chosenStock object though I get this error: [CFDictionary release]: message sent to deallocated instance 0x434d3d0

Ive tried using NSZombieEnabled and Build and Analyze to detect problems but no luck thus far. Ive even gone so far as to comment bits and pieces of the code with NSLog but no luck. I'll post the code for StockData below this. As far as I can figure something is getting deallocated before I do the release but I'm not sure how. The only place I've got release in my code is under dealloc method call.

Here's the StockData code:

// StockData contains all stock information pulled in through Yahoo! to be displayed

@implementation StockData

@synthesize ticker, values;

- (id) initWithContents: (NSString *)newName {
    if(self = [super init]){
        ticker = newName;
    }
    return self;
}

- (void) getData {

    NSURL *url = [NSURL URLWithString: [NSString stringWithFormat:@"http://download.finance.yahoo.com/d/quotes.csv?s=%@&f=%@&e=.csv", ticker, @"chgvj1"]];
    NSError *error;
    NSURLResponse *response;
    NSURLRequest *request = [NSURLRequest requestWithURL:url];

    NSData *stockData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

    if(stockData) {
        NSString *tempStr = [[NSString alloc] initWithData:stockData encoding:NSASCIIStringEncoding];       

        NSArray *receivedValuesArr = [tempStr componentsSeparatedByString:@","];
        [tempStr release];

        values = [NSDictionary dictionaryWithObjects:receivedValuesArr forKeys:[@"change, high, low, volume, market" componentsSeparatedByString:@", "]];
    } else {
        NSLog(@"Connection failed: %@", error);
    }
}

- (void)dealloc {
    [ticker release];
    [values release];   
    [super dealloc];

    NSLog(@"Release took place fine");
}

@end

© Stack Overflow or respective owner

Related posts about iphone

Related posts about count