0
votes

Recently I have finished my first Iphone app and it works grate.... except for when i did a intense session using instruments to find leaks after awhile with no leaks, all of a sudden get about 1.3Kb worth. In the stack trace they all point to the exact line that I release a UIViewControler on after pushing it to the Navigation controller (Ill post this code a bit further down). The Leak seem to happen after a few time navagating through the ViewControlers and back again. I know this is a very generally question but I hope someone could point me in the right direction. I have spent a few days trying to solve this and it is starting to dive me crazy!

My app is a Navigation based one, here is how it works in a nutshell:

Starts with a UIViewControler which when a button is pressed goes to another UIViewControler containing a TableView. From here depending on the contents of the array that populates the TableView it could go to a UIViewControler containing a PickerView then to the last UIViewControler or just go straight to the last UIViewControler bypassing the one with the PickerView.

Here is the code that the stack trace says the Leak is on:

SoundConfiger *third = [[SoundConfiger alloc] initWithNibName:@"SoundConfiger" bundle:[NSBundle mainBundle]];
    [third setTitle:@"Sound Link"];
    third.myData = myData;
    third.selectedRow = row;
    third.currentChoise = nil;
    [self.navigationController pushViewController:third animated:YES];
    [third release];    <---- Instruments says the leak is here on this line.

Shouldn't the NavigationController be responsible for this UIViewcontroler now? I have not called retain on third anywhere else and it only exists in this function.

I have a Bunch of Leaks from UIkit and QuartsZone. I have a screen shot bellow of some of them, in the stack traces all point to the same snippet of code, in the same function, in the same object as stated above at some point in the trace:

Here is a Link to the image as I can't post images yet: Link no longer valid

Here is the compleat stack trace from the first GeneralBlock-16 in the list. The one in bold (line 29) is the code snippet above:


0 libSystem.B.dylib malloc

1 CoreFoundation -[__NSArrayM insertObject:atIndex:]

2 CoreFoundation -[__NSArrayM addObject:]

3 UIKit -[UIView(UIViewGestures) addGestureRecognizer:]

4 UIKit -[UISwitch _commonInit]

5 UIKit -[UISwitch initWithCoder:]

6 UIKit UINibDecoderDecodeObjectForValue

7 UIKit UINibDecoderDecodeObjectForValue

8 UIKit -[UINibDecoder decodeObjectForKey:]

9 UIKit -[UIView initWithCoder:]

10 UIKit UINibDecoderDecodeObjectForValue

11 UIKit -[UINibDecoder decodeObjectForKey:]

12 UIKit -[UIRuntimeConnection initWithCoder:]

13 UIKit UINibDecoderDecodeObjectForValue

14 UIKit UINibDecoderDecodeObjectForValue

15 UIKit -[UINibDecoder decodeObjectForKey:]

16 UIKit -[UINib instantiateWithOwner:options:]

17 UIKit -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:]

18 UIKit -[UIViewController _loadViewFromNibNamed:bundle:]

19 UIKit -[UIViewController loadView]

20 UIKit -[UIViewController view]

21 UIKit -[UIViewController contentScrollView]

22 UIKit -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:]

23 UIKit -[UINavigationController _layoutViewController:]

24 UIKit -[UINavigationController _startTransition:fromViewController:toViewController:]

25 UIKit -[UINavigationController _startDeferredTransitionIfNeeded]

26 UIKit -[UINavigationController pushViewController:transition:forceImmediate:]

27 UIKit 0x6ea9b5

28 UIKit -[UINavigationController pushViewController:animated:]

29 Booby Trap -[SelectEventTypeviewcontroler ChooseThisOne] /Users/chriswyllie/Documents/Booby Trap/Booby Trap/Classes/SelectEventTypeviewcontroler.m:91

30 CoreFoundation -[NSObject(NSObject) performSelector:withObject:withObject:]

31 UIKit -[UIApplication sendAction:to:from:forEvent:]

32 UIKit -[UIApplication sendAction:toTarget:fromSender:forEvent:]

33 UIKit -[UIControl sendAction:to:forEvent:]

34 UIKit -[UIControl(Internal) _sendActionsForEvents:withEvent:]

35 UIKit -[UIControl touchesEnded:withEvent:]

36 UIKit -[UIWindow _sendTouchesForEvent:]

37 UIKit -[UIWindow sendEvent:]

38 UIKit -[UIApplication sendEvent:]

39 UIKit _UIApplicationHandleEvent

40 GraphicsServices PurpleEventCallback

41 CoreFoundation CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION

42 CoreFoundation __CFRunLoopDoSource1

43 CoreFoundation __CFRunLoopRun

44 CoreFoundation CFRunLoopRunSpecific

45 CoreFoundation CFRunLoopRunInMode

46 GraphicsServices GSEventRunModal

47 GraphicsServices GSEventRun

48 UIKit -[UIApplication _run]

49 UIKit UIApplicationMain

50 Booby Trap main /Users/chriswyllie/Documents/Booby Trap/Booby Trap/main.m:14

51 Booby Trap start


Thanks for your help in advance, I am hope I am just doing something silly and I need a fresh set of eyes to see it. Let me know If you need more info.

2

2 Answers

3
votes

Well I am a Tool :)

I was not handeling the IBOutlets correctly in each viewControler.

I was not declaring each IBOutlet using @property with a retain, using "self.someLabel = nil" (to release and set to the IBOutlets to nil) in the viewDidUnload method for a memory warning and then finally releasing in in dealloc.

thus tool. lol

What I was doing was declaring was "IBOutlet UILabel *someLabel;" in the header with no @property and this was causing the leaks seen above, they don't happen right away it takes a while and when they do the stack trace and every thing dose not help to much.

They only way I found what was leaking was striping everything out of my app and I mean everything until the leak went away.

Thanks for your help Ishu Gupta, I am glad we had a outcome.

Here are the relevant link to show how to do IBOutlets correctly: What happens if I don't retain IBOutlet?

0
votes

SoundConfiger *third = [[[SoundConfiger alloc] initWithNibName:@"SoundConfiger" bundle:[NSBundle mainBundle]] autorelease];

and remove

[third release]; this line.

You can fix only those leaks which comes because of your code(forget release any object or some wrong things). But some time you get extra leaks these are present in iphone sdk. Actully some of functions or properties of iPhone having leaks.so these can be fixed only when you change the use of these. And one thing more 1.3 KB leak is not bad if it will not be increase with app operations.