[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSBundle requires an NSAutoreleasePool

From: Luboš Doležel
Subject: NSBundle requires an NSAutoreleasePool
Date: Tue, 16 Oct 2012 12:07:39 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120907 Thunderbird/15.0.1


see the attached very simple program. If you run it the way it is, it will crash.

#0 0x00007ffff75fbef0 in -[NSException raise] () from /usr/lib64/ #1 0x00007ffff752d8a4 in -[GSMutableDictionary setObject:forKey:] () from /usr/lib64/ #2 0x00007ffff7586ca4 in -[NSBundle localizedStringForKey:value:table:] () from /usr/lib64/ #3 0x00007ffff76cf2a0 in +[NSTimeZone systemTimeZone] () from /usr/lib64/ #4 0x00007ffff76ce847 in +[NSTimeZone defaultTimeZone] () from /usr/lib64/ #5 0x00007ffff76cc120 in -[NSLocalTimeZone secondsFromGMTForDate:] () from /usr/lib64/ #6 0x00007ffff759390b in -[NSCalendarDate descriptionWithCalendarFormat:locale:] () from /usr/lib64/ #7 0x00007ffff7591c56 in -[NSCalendarDate descriptionWithCalendarFormat:] () from /usr/lib64/
#8  0x00007ffff763bf30 in NSLogv () from /usr/lib64/
#9  0x00007ffff763bc34 in NSLog () from /usr/lib64/
#10 0x00007ffff757e106 in +[NSAutoreleasePool addObject:] () from /usr/lib64/ #11 0x00007ffff765140c in -[NSObject autorelease] () from /usr/lib64/ #12 0x00007ffff75efca5 in +[NSDictionary dictionary] () from /usr/lib64/ #13 0x00007ffff75805a0 in +[NSBundle initialize] () from /usr/lib64/ #14 0x00007ffff7bc2626 in objc_send_initialize (object=<optimized out>) at dtable.c:733 #15 0x00007ffff7bcbb26 in objc_msg_lookup_internal (receiver=<optimized out>, selector=<optimized out>, receiver=<optimized out>, selector=<optimized out>, sender=<optimized out>) at sendmsg2.c:73 #16 objc_msg_lookup (receiver=<optimized out>, selector=<optimized out>) at sendmsg2.c:398
#17 0x000000000040087a in main () at bundletest.m:7

Uncomment the single commented line and it starts working.

+[NSDictionary dictionary] assumes that there is an autorelease pool.

1) Is this assumption correct? Apple's documentation says nothing about using autorelease.

2) If it is so, then callers of this method - such as [NSBundle initialize] - should create their own pool instead of relying on the app to do that.

3) NSBundle should check that the call hasn't looped back before the initialization is complete.

What do you think?
Luboš Doležel

Attachment: bundletest.m
Description: Text document

reply via email to

[Prev in Thread] Current Thread [Next in Thread]