Search code examples
iphoneiosinstrumentsmemory-leaks

Fix leaks from main.m


Instruments - Leaks is used to profile myApp. The result is as following:

Leaks

   #    Address     Category      Event Type    RefCt      Timestamp    Size    Responsible Library Responsible Caller
   0    0xe8b8120   Malloc 48 Bytes Malloc        1      00:30.130.300  48             myApp            main

Stack Trace

   0 libsystem_c.dylib 0x36fa9be3
   1 libsystem_c.dylib 0x36fae57c
   2 libnotify.dylib 0x364fe126
   3 libnotify.dylib 0x364ff392
   4 libnotify.dylib 0x364ff4fc
   5 CoreFoundation 0x35276af4
   6 CoreFoundation 0x35278066
   7 UIKit 0x324448d4
   8 UIKit 0x32426648
   9 UIKit 0x324432d4
  10 UIKit 0x324207ba
  11 UIKit 0x323b0f0c
  12 UIKit 0x325e1564
  13 UIKit 0x3232d0fc
  14 UIKit 0x3232bc4a
  15 UIKit 0x32338990
  16 UIKit 0x323387ce
  17 UIKit 0x3233839c
  18 UIKit 0x3231e83c
  19 UIKit 0x3231e0e2
  20 GraphicsServices 0x3655322a
  21 CoreFoundation 0x352d4522
  22 CoreFoundation 0x352d44c4
  23 CoreFoundation 0x352d3312
  24 CoreFoundation 0x352564a4
  25 CoreFoundation 0x3525636c
  26 GraphicsServices 0x36552438
  27 UIKit 0x3234ce7c
  28 myApp main /Developer/+Projects/myApp/myApp/main.m:16
  29 myApp start

Actually I have no idea how to fix leaks from main.m. How could I fix this problem? Thanks in advance!

Edit 1

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
  //line 16
    }
}

Solution

  • This appears to be a bug in iOS 5.1, I've noticed it myself and seen it mentioned in other threads such as this one. The issue has been raised in the official Apple Dev forums as well. So unfortunately it appears there's nothing we can do about it for now, it'll very likely be addressed in the upcoming iOS 6. As a minor consolation, the leak is not massive (48 bytes each time, if the app runs for a large amount of time it could start affecting performance but very marginally) and shouldn't be a show-stopping issue.

    All we can do for now is wait for Apple to fix things on their end, while we focus on not making any other leaks in our apps!