tags:

views:

18

answers:

2

Hello All,

Currently My application is getting crashed on accessing NSString after bringing application to foreground from background [on 4.0 OS].

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

iDatabasePath  = [documentsDirectory stringByAppendingPathComponent:KApp_DB_Name]; 

iDatabasePath is declared as NSString* and it is globally declared.

When Application is moved to background and brought to foreground when I make a call to

 iDatabasePath  = [documentsDirectory stringByAppendingPathComponent:KApp_DB_Name]; 

Application crashes due to EXC_BAD_ACCESS to iDatabasePath and this is happening on 4.0 OS

Please help me on this.

Thanks,

Sagar

A: 

you need to retain it...

[iDatabasePath retain] somewhere - probably applicationDidEnterBackground

Thomas Clayson
I did that, but no use. still it gives me bad access.
Sagar Mane
what about retaining documentsDirectory? and/or paths?
Thomas Clayson
If I try to retain those on applicationDidEnterBackground I get error -[NSPathStore2 retain]: message sent to deallocated instance
Sagar Mane
hmm... try looking up NSZombiesEnabled. This might help you debug. It sounds like the object is running its dealloc method, and thus releasing your pointers before applicationDidEnterBackground gets called.
Thomas Clayson
A: 

so which line is the error on? If its on the line you say, it looks like documentsDirectory would be getting released, not iDatabasePath, have you tried to retain iDatabasePath?

Mark
it is giving me error on iDatabasePath = [documentsDirectory stringByAppendingPathComponent:KApp_DB_Name]; but if I make iDatabasePath local then it works.
Sagar Mane