views:

97

answers:

2

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

+3  A: 

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

Jasarien
I didn't have it there originally and had the error, added it because i thought that might help. Just removed it and still get the same error.
padatronic
(thanks for replying so fast!)
padatronic
If it's fully implemented as a singleton, any calls to release should just be ignored by the instance
Claus Broch
@Claus, correct. @padatronic, if that's the case, you're not managing the MediaData singleton's memory properly. Look up on implementing Singletons properly, as Claus suggests.
Jasarien
Right chaps thanks for the help, seem to have fixed it. I am autoreleaseing my objects and this seems to have fixed it. not completely sure what was happening, have a feeling I will understand it properly soon
padatronic
+1  A: 

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

Gordon Christie