“Object 0x84be00 of class NSCFString autoreleased with no pool in place - just leaking” - but on the first line of the app!

有些话、适合烂在心里 提交于 2019-12-05 20:28:44

You likely have a constructor somewhere that is running before main() that is triggering this problem. What libraries are you linking against and/or are you using any __attribute__ directives?


Herp.

Realized something obvious. Since the objects are leaked, they still exist. Set a breakpoint on main() and then, at the GDB prompt, type po 0x84be00 (only replace 0x84be00 with the address of one of the strings that was leaked).

That'll show you the contents of that string and give you a very good clue as to what the cause is.

Derp.

Set a breakpoint on __NSAutoreleaseNoPool and see what the backtraces show you.

I fail at the obvious today (only obvious because I've been down this road 18.27314 million times).

You have a static variable somewhere in the app that is being initialized outside the main runloop. Something like:

static UIImage *myImage = [UIImage imageNamed:@"fred.png"];

Look for any static variables that initialize objects, and initialize them in something like applicationDidFinishLaunching to set them up with an autorelease pool in place.

Even though it says an NSString is leaking it could be any kind of object.

In apps using background threads you need to create an autorelease pool within the background method:

-(void)myMethodThatRunsOnBackground:(id)param {
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

  //body of method

  [pool release];
}

answer credit: nobre84 on iphonedevsdk.com

I was looking for an answer to this problem, but I managed to work out what the problem was after some research. I too had this error which occurred before main was executed and I tracked it down through me implementing a method called + (void)load which I thought was a great name to load some global class specific data. I did not realise that load was actually already defined and me using it was overriding the default load, and load is executed before main. Thus I was leaking. Renaming it to myload fixed it.

You could try to put a symbolic breakpoint for autorelease to see where and when this is being called.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!