views:

81

answers:

1

Hi, I do not understand why Instruments/Leaks tells me that there is a memory leak in my viewDidLoad. I do release both objects in dealoc and set them to nil in viewDidUnload. Can someone give me a clue here?

Link to screen-dump from Instruments: http://i26.tinypic.com/28227iw.png

BR //Christoffer

+1  A: 

I do release both objects in dealoc and set them to nil in viewDidUnload

I might be misunderstanding the grammer of the sentence, but you should release and set to nil in both dealloc and viewDidUnload.

As a general rule, you should always release and set to nil as a pair unless you have a specific reason not to.

Akusete
Not to mention that just releasing an object without setting references to it to nil is plain dangerous.
Costique
Thanks for your replies. I see the error/flaws in the code that you point out and corrected them. But the result is the same. So how should this be implemented if you want to initialize class objects each time the view loads?
Christofffer
You should release them in viewUnload and create them in viewLoad
Akusete
Ok I got it to work by initializing the NSMutableArray in another way:This Work: self.listOfItems = [[NSMutableArray alloc]init];self.paymentmethods = [[NSMutableArray alloc]init];This does not work:self.listOfItems = [[NSMutableArray array]retain];self.paymentmethods = [[NSMutableArray array]retain];Do you guys know why the other causes a leak?
Christofffer
Both of those leak, assuming the properties are retained.
tc.