Reputation: 3760
objc[23601]: Object 0x12b090f0 of class __NSCFSet autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
Why would the following code section print the leak error above?
+ (BOOL)getSkipFlag
{
NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
if ( ![defs objectForKey:_BOOK_ID] )
{
[defs setObject:@"yyyy" forKey:_BOOK_ID];
[defs synchronize];
}
if ( ![[defs objectForKey:_BOOK_ID] isEqualToString:@"xxxx"] )
{
return NO;
}
return skipFlag;
}
usage
if ( ![ClassXYZ getSkipFlag] )
....
I don't use a new thread so I should not have a new autorelease pool set up.
Note: NSString *temp = [[NSBundle mainBundle] pathForResource:_CONFIG_PLIST ofType:@"plist"];
- would print the same error
I am using iOS 5.1
Thanks for any insight.
UPDATE: ClassXYZ.m ... static BOOL skipFlag = NO;
setter: + (void)setSkipFlag:(BOOL)boolValue { skipFlag = boolValue; }
usage: [ClassXYZ setSkipFlag:YES];
used in static void convert_uri_to_file_name(struct mg_connection *conn, const char *uri, char *buf, size_t buf_len)
Omar you had a good point about where it is used. It turns out if I ClassXYZ's own instance methods for example, it works without errors.
Upvotes: 0
Views: 566
Reputation: 21221
just out of curiosity, if you put the function call inside an @autorelease
that log should go away
Upvotes: 0
Reputation: 9718
Generally, The autorelease pool for main thread would be created at the first line of main
function. Anything that runs before main
function would see that the autorelease pool is absent.
+load
function is one reason that would cause the leaks, because it runs before main
function. If that's the case, just consider using +initialize
instead.
Upvotes: 1