Dev1345
Dev1345

Reputation: 61

Can someone help with memory leak problem?

I'm a newbie trying to figure out a memory leak problem. Does anyone see anything wrong with the following code?

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController.navigationBar setTintColor:[UIColor colorWithRed:0.10 green:.20 blue:0.30 alpha:1]];
}

In case it helps, Instruments shows the leaked block with the following info...

Event Type: Malloc

Responsible Library: CoreGraphics

Responsible Caller: CGTypeCreateInstanceWithAllocator

Any help would be greatly appreciated. (I'm still very new, so please explain in as much detail as possible.)

Much thanks!

Upvotes: 0

Views: 475

Answers (2)

Paul.s
Paul.s

Reputation: 38728

Bit of a long shot but I'm not sure if it was just a bug in my project or not but I had a similar issue once when setting tintColor in viewWillAppear. I ended up adding an nil check before assigning the color again and this cleared it up for me (I didn't do any further investigation into it so I could be wrong).

if (nil == self.navigationController.navigationBar.tintColor) {
  self.navigationController.navigationBar = [UIColor colorWithRed:0.10 green:.20 blue:0.30 alpha:1];
}

Upvotes: 1

sergio
sergio

Reputation: 69027

The code you have posted is correct, as far as memory management is concerned.

Instruments Leaks will simply show the point where the leaked object is allocated, not the point where it is actually leaked.

So, your leak is elsewhere. Looking at your code, I would say that the leak is possibly occurring when you release the class containing that code, or elsewhere along the dynamical path to dealloc.

Try commenting out setTintColor to check whether the leak is still there.

Hope this explanation can put you on the right track, but in any case, if you need more help, you should post more code...

Upvotes: 1

Related Questions