15

I am developing an app using ARC When profiling my app in instruments for memory leaks it shows leaks at the following function:

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc, char *argv[])

{
    @autoreleasepool { 
       return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

Does this indicate a problem somewhere else in my code?

This is the stack trace

   0 libsystem_c.dylib malloc
   1 libsystem_c.dylib strdup
   2 libnotify_sim.dylib token_table_add
   3 libnotify_sim.dylib notify_register_mach_port
   4 libnotify_sim.dylib notify_register_dispatch
   5 CoreFoundation _CFXNotificationRegisterObserver
   6 CoreFoundation CFNotificationCenterAddObserver
   7 UIKit -[UIScrollView(Static) _startTimer:]
   8 UIKit -[UIScrollView _endPanWithEvent:]
   9 UIKit -[UIScrollView handlePan:]
  10 UIKit _UIGestureRecognizerSendActions
  11 UIKit -[UIGestureRecognizer _updateGestureWithEvent:]
  12 UIKit -[UIGestureRecognizer _delayedUpdateGesture]
  13 UIKit ___UIGestureRecognizerUpdate_block_invoke_0541



14 UIKit _UIGestureRecognizerApplyBlocksToArray
  15 UIKit _UIGestureRecognizerUpdate
  16 UIKit -[UIWindow _sendGesturesForEvent:]
  17 UIKit -[UIWindow sendEvent:]
  18 UIKit -[UIApplication sendEvent:]
  19 UIKit _UIApplicationHandleEvent
  20 GraphicsServices PurpleEventCallback
  21 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__
  22 CoreFoundation __CFRunLoopDoSource1
  23 CoreFoundation __CFRunLoopRun
  24 CoreFoundation CFRunLoopRunSpecific
  25 CoreFoundation CFRunLoopRunInMode
  26 GraphicsServices GSEventRunModal
  27 GraphicsServices GSEventRun
  28 UIKit UIApplicationMain
  29 MyProject/main.m:16
  30 MyProject start
Tassos Voulgaris
  • 878
  • 1
  • 9
  • 21
  • do you have any specific logs & error codes? since you did not write this function yourself the problem wil lie within your own code =) – Sebastian Flückiger Mar 18 '12 at 12:25
  • Does this leak entry in instruments help? I get around 10 entries like this for a two minute run of my app: Leaked object: Malloc 48 bytes, Responsible library: libsystem_c.dylib Responsible frame: strdup. – Tassos Voulgaris Mar 18 '12 at 12:46
  • you should be able to click on the adress of this malloc block & get a stack trace from there that should help you figure out where it comes from. but to be very honest - 10x 48 bytes of leak is not the ends world if it stays at this ;) – Sebastian Flückiger Mar 18 '12 at 12:49
  • Thanks for your reply. I have updated my question with the stack trace, in case you want to have a look. I am not experienced enough to understand where the leak lies in the stack trace – Tassos Voulgaris Mar 18 '12 at 13:05
  • i'm out of my domain now, too - but i think with this additional information someone else might be able to help you :) – Sebastian Flückiger Mar 18 '12 at 13:28
  • Long shot, but perhaps you've missed a `[super dealloc]` somewhere in your code when you've subclassed a view controller? – joerick Mar 18 '12 at 13:54
  • [super dealloc] is not allowed when using ARC – Tassos Voulgaris Mar 20 '12 at 15:50

3 Answers3

22

It seems to be a bug in the iOS 5.1 framework: https://devforums.apple.com/message/630695

ianolito
  • 3,651
  • 1
  • 19
  • 18
1

I had this same problem while using ARC and it was caused by having the dealloc function in a view controller. By having the dealloc function (that didn't do anything in my case), the default behavior may not be called. Try commenting out all instances of dealloc and that should fix your problem.

brendan
  • 1,705
  • 1
  • 18
  • 24
  • I was using FMDatabase for sqlite which had calls to super dealloc. I have commented the super dealloc out, but instruments still show leaks in the same place. I have no more dealloc anywhere in my project – Tassos Voulgaris Mar 21 '12 at 17:15
0

Your main.m looks different than others I have seen. Did you format it that way or was it done that way automatically? Here is an example from one of my ARC apps.

int main(int argc, char *argv[]) {

    @autoreleasepool {
        int retVal = UIApplicationMain(argc, argv, nil, nil);
        return retVal;
    }
}
Bill Burgess
  • 14,054
  • 6
  • 49
  • 86