IOS What is done before main ()?

objc[1655]: Object 0x2314e0 of class __NSCFString autoreleased with no
pool in place - just leaking - break on objc_autoreleaseNoPool() to
debug

objc[1655]: Object 0x2315e0 of class NSPathStore2 autoreleased with
no pool in place - just leaking - break on objc_autoreleaseNoPool() to
debug

objc[1655]: Object 0x2316b0 of class __NSCFData autoreleased with no
pool in place - just leaking - break on objc_autoreleaseNoPool() to
debug

File:MultiFormatReader.mm Method:+[MultiFormatReader load]  --

objc[1655]: Object 0x2317e0 of class __NSCFString autoreleased with
no pool in place - just leaking -  break on objc_autoreleaseNoPool()
to debug

objc[1655]: Object 0x231800 of class __NSCFData autoreleased with no
pool in place - just leaking
- break on objc_autoreleaseNoPool() to debug

..++++++++

File:main.mm  Method:main  -- mark..

File:BarcodesAppDelegate.m  Method:-[BarcodesAppDelegate
application:didFinishLaunchingWithOptions:]  -
File:BarcodesAppDelegate.m  Method:-[BarcodesAppDelegate
application:didFinishLaunchingWithOptions:]  -

This is the relative code:

+ (void)load {
    MPLog(@" ..++++++++");
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    [FormatReader registerFormatReader:[[[self alloc] init] autorelease]];
    [pool drain];
}


int main(int argc, char *argv[]) {
    MPLog(@"mark..");
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
}

This is my debugging message, I used the zxing framework in my APP, but I found that some other code was still running before calling the main () method. What for? generally speaking, what is done before main ()? What does this program mean " objc[1655]: Object 0x2314e0 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug"?

+3
source share
3 answers

Move 2 MPLogbelow NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];?

+ (void)load {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    MPLog(@" ..++++++++");
    [FormatReader registerFormatReader:[[[self alloc] init] autorelease]];
    [pool drain];
}


int main(int argc, char *argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    MPLog(@"mark..");
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
}
+2
source

Set a symbolic breakpoint at objc_autoreleaseNoPoolto stop execution when this error occurs. You can then determine where you need to place the auto-detection pools (explicitly).

generally speaking, what is excute before main ()?

from + [NSObject load] docs:

, Objective-C ; , , .

+ (void)load

, , , .

:

  • , .
  • + .
  • ++ C/++ __attribute__(constructor) .
  • , .

:

  • classs + load + .
  • + load own + load .
  • , , , , .
+1

I see this problem. If I set a breakpoint in objc_autoreleaseNoPool, in the main thread, I get the following useless stack trace:
0 0x332097b8 in objc_autoreleaseNoPool ()
1 0x331fe7b8 in (anonymous namespace)::AutoreleasePoolPage::autoreleaseSlow(objc_object*) ()
2 0x332098de in _ZL22_objc_rootAutorelease2P11objc_object ()
3 0x331fcdb6 in _objc_rootAutorelease ()

It seems like he hit an auto-detection error before anything in the application really started. Could this be the result of some loading methods in one of the frameworks that I included in the project?

0
source

All Articles