Iphone memory leak
I posted this issue a few days ago, but it was very confusing and my question was not very clear, so I deleted it. I've been digging around and the memory leak still persists. Hopefully this attempt is clearer.
First, I ran a static analyzer and it does not report a memory leak.
Then I ran Tools and it pointed out a memory leak on that line of code. As far as I can see, there is no memory leak.
featured=[[UILabel alloc]initWithFrame:CGRectMake(130,15, 200, 15)];
//[featured setFont:[UIFont UIFontboldSystemFontOfSize:20]];
featured.font = [UIFont boldSystemFontOfSize:20];
featured.backgroundColor= [UIColor clearColor];
featured.textColor=[UIColor blackColor];
featured.text= @"Featured Promo";
[self.view addSubview:featured];
[featured release];
featured=nil;
If I comment out the above code, the tools are reporting another memory leak in a different block of code where there is no discernible leak.
UIButton *populartbutton = [[UIButton buttonWithType:UIButtonTypeRoundedRect]];
populartbutton.frame = CGRectMake(112, 145, 90, 22); // size and position of button
[populartbutton setTitle:@"Popular" forState:UIControlStateNormal];
populartbutton.backgroundColor = [UIColor clearColor];
populartbutton.adjustsImageWhenHighlighted = YES;
[populartbutton addTarget:self action:@selector(getpopular:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:populartbutton];
Tools also say
Responsible library = Core Graphics
Responsible frame = open_handle_to_dylib_path
This is a stack trace.
53 Promo start
52 Promo main /Users/..2/main.m:14
51 UIKit UIApplicationMain
50 UIKit -[UIApplication _run]
49 CoreFoundation CFRunLoopRunInMode
48 CoreFoundation CFRunLoopRunSpecific
47 GraphicsServices PurpleEventCallback
46 UIKit _UIApplicationHandleEvent
45 UIKit -[UIApplication sendEvent:]
44 UIKit -[UIApplication handleEvent:withNewEvent:]
43 UIKit -[UIApplication _reportAppLaunchFinished]
42 QuartzCore CA::Transaction::commit()
41 QuartzCore CA::Context::commit_transaction(CA::Transaction*)
40 QuartzCore CALayerLayoutIfNeeded
39 QuartzCore -[CALayer layoutSublayers]
38 UIKit -[UILayoutContainerView layoutSubviews]
37 UIKit -[UINavigationController _startDeferredTransitionIfNeeded]
36 UIKit -[UINavigationController _startTransition:fromViewController:toViewController:]
35 UIKit -[UINavigationController _layoutViewController:]
34 UIKit -[UINavigationController_computeAndApplyScrollContentInsetDeltaForViewController:]
33 UIKit -[UIViewController contentScrollView]
32 UIKit -[UIViewController view]
31 Promo -[FeaturedLevelViewController viewDidLoad] /Users/..s/FeaturedLevelViewController.m:67 // THIS IS MY CLASS WHERE THE CODE SAMPLES ABOVE ARE FROM
30 UIKit -[UILabel initWithFrame:]
29 UIKit -[UILabel _commonInit]
28 UIKit +[UILabel defaultFont]
27 UIKit +[UIFont systemFontOfSize:]
26 GraphicsServices GSFontCreateWithName
25 CoreGraphics CGFontCreateWithName
24 CoreGraphics CGFontCreateWithFontName
23 CoreGraphics CGFontFinderGetDefault
22 CoreGraphics CGFontGetVTable
21 libSystem.B.dylib pthread_once
20 CoreGraphics load_vtable
19 CoreGraphics load_library
18 CoreGraphics CGLibraryLoadFunction
17 CoreGraphics load_function
16 CoreGraphics open_handle_to_dylib_path
15 libSystem.B.dylib dlopen
14 dyld dlopen
13 dyld dyld::link(ImageLoader*, bool, ImageLoader::RPathChain const&)
12 dyld ImageLoader::link(ImageLoader::LinkContext const&, bool, bool, ImageLoader::RPathChain const&)
11 dyld ImageLoader::recursiveLoadLibraries(ImageLoader::LinkContext const&, bool, ImageLoader::RPathChain const&)
10 dyld dyld::libraryLocator(char const*, bool, char const*, ImageLoader::RPathChain const*)
9 dyld dyld::load(char const*, dyld::LoadContext const&)
8 dyld dyld::loadPhase0(char const*, dyld::LoadContext const&, std::vector<char const*, std::allocator<char const*> >*)
7 dyld dyld::loadPhase1(char const*, dyld::LoadContext const&, std::vector<char const*, std::allocator<char const*> >*)
6 dyld dyld::loadPhase3(char const*, dyld::LoadContext const&, std::vector<char const*, std::allocator<char const*> >*)
5 dyld dyld::loadPhase4(char const*, dyld::LoadContext const&, std::vector<char const*, std::allocator<char const*> >*)
4 dyld dyld::loadPhase5(char const*, dyld::LoadContext const&, std::vector<char const*, std::allocator<char const*> >*)
3 dyld dyld::mkstringf(char const*, ...)
2 dyld strdup
1 dyld malloc
0 libSystem.B.dylib malloc
I'm really not too sure how to use this information to troubleshoot the problem, so any guidance would be greatly appreciated. Maybe the answer is in the trail, but I just don't know what to look for?
EDIT ::
The above stack trace is done while running on the simulator. Below is a description of the operation on the device. This trace does not point to any of my own classes
23 Promo 0x0
22 libSystem.B.dylib _pthread_body
21 Foundation __NSThread__main__
20 Foundation +[NSThread exit]
19 libSystem.B.dylib _pthread_exit
18 libSystem.B.dylib _pthread_tsd_cleanup
17 QuartzCore CA::Transaction::release_thread(void*)
16 QuartzCore CA::Transaction::commit()
15 QuartzCore CA::Context::commit_transaction(CA::Transaction*)
14 QuartzCore CALayerDisplayIfNeeded
13 QuartzCore -[CALayer display]
12 QuartzCore -[CALayer _display]
11 QuartzCore CABackingStoreUpdate
10 QuartzCore backing_callback(CGContext*, void*)
9 QuartzCore -[CALayer drawInContext:]
8 UIKit -[UIView(CALayerDelegate) drawLayer:inContext:]
7 UIKit -[UILabel drawRect:]
6 UIKit -[UILabel drawTextInRect:]
5 UIKit -[UILabel _drawTextInRect:baselineCalculationOnly:]
4 UIKit -[NSString(UIStringDrawing) drawAtPoint:forWidth:withFont:lineBreakMode:]
3 UIKit -[NSString(UIStringDrawing) drawAtPoint:forWidth:withFont:lineBreakMode:letterSpacing:includeEmoji:]
2 WebCore WKSetCurrentGraphicsContext
1 WebCore CurrentThreadContext()
0 libSystem.B.dylib calloc
EDIT 2 ::
I noticed a leak that was reported earlier in the application lifecycle. He points to this code block.
Is this the generated x code when you do the project right?
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}
a source to share
First, you can ignore everything the simulator tells you about the memory leak - it uses different memory management and is known to cause some false positives.
Second, how big is the leak? If your code doesn't show up in the stack trace and the leak is small, ignore it - it's either a leak in some Apple library (unlikely), or it's tools messed up with frameworks. There is nothing you can do about it anyway.
In your case it looks like something with UIFont loading; the data for them will probably be available for different applications anyway, so they can be ignored!
As far as your code snippets are concerned, there are no obvious leaks that I can see :)
Hope it helps,
Sam
a source to share