Xcode 4.6.2: Unrelated code clangs "potential leak" of contextInfo
Xcode 4.6.2: Unrelated code clangs "potential leak" of contextInfo
- Subject: Xcode 4.6.2: Unrelated code clangs "potential leak" of contextInfo
- From: Jerry Krinock <email@hidden>
- Date: Mon, 22 Apr 2013 11:52:41 -0700
First of all, let me say that I know retaining contextInfo and releasing it in a callback is not a good idea, but this is old code with manual memory management.
Since updating to Xcode 4.6.2, Analyze is reporting "potential leaks" with several of my many such contextInfo callbacks. I've isolated it to the following demo project, which creates and retains two objects, foo and bar, and passes them as contextInfo to callbacks. The callback receiving foo just autoreleases it. The callback receiving bar autoreleases it and also logs "Hello World" in a loop. When I "Analyze" this in Xcode, there is no complaint regarding foo, but
Potential leak of an object stored into 'bar'.
In real life, my actual callback has a bunch of other code, but for some reason it's only a loop that bothers it. In the demo, if I remove the for(;;) and just say "Hello World", or if I remove the "Hello World", I get a nice clean Analyze with no issues.
What might be going on here?
Thanks,
Jerry
#import <Foundation/Foundation.h>
@interface MyObject : NSObject
@end
@implementation MyObject
- (void)doFooWithContextInfo:(void*)contextInfo {
NSObject* object = (NSObject*)contextInfo ;
[object autorelease] ;
}
- (void)doBarWithContextInfo:(void*)contextInfo {
NSObject* object = (NSObject*)contextInfo ;
[object autorelease] ;
// Unrelated, senseless loop
for (NSObject* bird in [NSSet set]) {
NSLog(@"Hello world") ;
}
}
- (void)clangTest {
id foo = [[NSObject alloc] init] ;
[self doFooWithContextInfo:foo] ;
id bar = [[NSObject alloc] init] ;
[self doBarWithContextInfo:bar] ;
}
@end
int main(int argc, const char * argv[])
{
@autoreleasepool {
MyObject* myObject = [[MyObject alloc] init] ;
[myObject clangTest] ;
[myObject release] ;
}
return 0;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden