tags:

views:

99

answers:

2

I must be getting a memory leak, I'm calling a graph library view and the view shows the first time I use this button method, but the second time the app crashes, with no real error message, that I can see.

-(IBAction)graphNavButtonPressed
{   
    UIViewController *vc = [[GraphController alloc] init];

    [vc setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
    [self presentModalViewController:vc animated:YES];  // APP FAILS ON THIS LINE
    [vc release];
    return;
}

Program received signal:  “EXC_BAD_ACCESS”.
(gdb) bt
#0  0x02889903 in objc_msgSend ()
#1  0x0279a1c0 in __useVolatileDomainsForUser ()
#2  0x0267120c in CFPreferencesCopyAppValue ()

EDIT:

In GraphController ViewDidLoad I've got this code.

NSUserDefaults *myDefaults = [NSUserDefaults standardUserDefaults];
strCurrencySymbol = [myDefaults objectForKey:kNSUCurrency]; //HERE where it crashes

EDIT 2:

Ive been reading about someone with a similar problem, caused by a view being loaded incorrectly. link text I am doing something perhaps a little odd. In order to use the graph library from a tab bar, I load my date range view and then show the graph in viewDidLoad, then once the graph is closed the date range view remains. The user can then click view graph again to show the graph with different dates. If I don`t do this my view will be blank when the graph is closed. So heres how Im calling the graph.

alt text

I`m reusing the date range screen elsewhere so the graph may not be shown.

Any further suggestions ?

A: 

I guess you should not release the vc object in the same IBAction, because you are probably using it after arent you? not sure

JonLOo
Thats weird, I tried autorelease instead and it worked a little longer then crashed, I took out release and it works fine now. I don't understand why this is happening I though we always had to release if we used alloc etc.
Jules
Because if you allocate memory for an object, and you release it while you are using it its normal to get the crash, you have to release the object when you have finished working with it.
JonLOo
probably you program is trying to acces the object after that IBAction, so you are getting the crash, maybe you should declare your UIView controller outside the IBAction method, alloc it in the method and release it when you have finished with it
JonLOo
This answers makes no sense, the controller is in the local scope and cannot be used outside this code.
willcodejavaforfood
@willcodejava: you are right
vodkhang
@JonLo - That is not possible. It is defined in the local scope and he claims it fails on the presentModalViewController call...
willcodejavaforfood
but he told us that it worked if he does not release the vc object, i dont understand that
JonLOo
presentModalViewController looks like its not being able to acces the vc object so maybe he is releasing the object too soon no?
JonLOo
The thing is reuse the screen where the graphNavButtonPressed is defined, its a date range screen, with some views I don't use the graph, would it still be best to define vc outside of the button event method ?
Jules
Im not sure if it is the best way or not, but it looks like it will fit you
JonLOo
A: 

The code you've posted is correct in terms of memory management. If you're having problems on presentation of the VC (or on its release) check memory management in the init, viewDidLoad, and dealloc of the GraphController. The problem's most likely in there somewhere.

Also, that stack trace looks like something in the graphing library is trying to acccess user preferences and failing, so I'd check GraphController for calls to CFPreferencesCopyAppValue and make sure it's being called properly.

kevboh
See edit above, not sure why this should be causing the crash ?
Jules
Odd, the edit makes it look like standardUserDefaults is returning released memory. Try stepping through the debugger around there to see what exactly is happening.
kevboh
Its definitely that line.
Jules
See further info above
Jules