iPhone, Why am I getting a memory leak and how do i fix it? – Education Career Blog

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.

    UIViewController *vc = GraphController alloc init;

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

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


In GraphController ViewDidLoad I’ve got this code.

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


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 ?


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


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.

Leave a Comment