开发者

Why do I have a memory leak in UIApplication

开发者 https://www.devze.com 2022-12-30 19:22 出处:网络
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:

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开发者_StackOverflow中文版 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;


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];
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消