padatronic
padatronic

Reputation: 98

EXC_BAD_ACCESS error when my view controller tries to access a singleton variable a second time

I have an app i building which is a simple naviagtion app. I do not want to load the data from my xml multiple times so I am using a singleton to load and hold the data. My first table pushes the view of the second table. This table calls the singleton and the get the array of data from there to display in the table.

This all works fine, I click on a cell in the first table which takes me to the second table where the singleton is used. I navigate back to the the first table, then back to the second table, this is when i get the EXC_BAD_ACCESS error. It doesn't error when i init the singleton but when I try and access the array in it. The code is as follows

MediaData *dataClass = [MediaData sharedManager];

//when i check in the singleton the second time sharedManager is already there

sortedData = dataClass.arrMediaData; //this line errors the second time

NSLog(@"sorted array. %@", sortedData);

[dataClass release];

Any help would be great as it is not a very descriptive error, thanks

Upvotes: 1

Views: 404

Answers (2)

Gordon Christie
Gordon Christie

Reputation: 609

As Jasarien said, don't release the singleton.

You can use NSZombieEnabled and run on a device to get more descriptive errors: http://www.cocoadev.com/index.pl?NSZombieEnabled

Upvotes: 1

Jasarien
Jasarien

Reputation: 58448

The last line in your code is causing the issue. Singletons shouldn't be released.

Upvotes: 3

Related Questions