views:

182

answers:

2

I have an iphone app project. I analysed it using instruments memory leak tool. According to instruments I have 2 leaks the Trace is as follows:

start main UIAplicationMain _run CFRunLoopInMode CFRunLoopRunSpecific PurpleEventCallback _UIAplicationHandleEvent sendEvent: handleEvent:withNewEvent:

After this trace there are two separate traces. What causes this and how can I fix it?

edit: The leak is on the second line according to instruments

 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil); //leak
[pool release];
return retVal;
A: 

Are you missing a NSAutoReleasePool for the threads?

That second method looks like some sort of callback being invoked by another component or system thread.

In the implementation, create a NSAutoReleasePool at the top and release it when the method is done:

void MyCallback {
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  // do stuff
  [pool release];
}
psychotik
When I first created the project(window based application template) I used the main.m that was created. According to instruments their is a leak on the second line: NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, nil); [pool release]; return retVal;
A: 

It might be a false positive. UIApplicationMain probably creates a few objects that are intended to hang around for as long as the application exists and therefore never bothers to release them.

JeremyP