Why is main leaking in my iPhone app? - iphone

See the screenshot below, this is the only leak the Leaks Instrument finds in my app. Seems odd that main is leaking since it's out-of-the-box. Is this common?

This usually indicates that the leak is occurring somewhere before the app delegate loads. Check any added resources like compiled libraries.
Drag this code source or your app delegate source into Instruments and it might show you the call stack so you can track it down.
Edit01:
See IPHONE: Analyzing leaks with instruments for an example of how to view source in Instruments.

Related

How to exactly find where memory is leaking in project of iPhone

While developing apps in Xcode memory leaks are occurring. When I checked them in extended detail view they are showing different methods that are not related to implemented. How to exactly find out which object is leaking and where it is leaking memory.
When ARC is enabled we have to take care of memory leaks or not?
Even with ARC memory leaks can occur, it just inserts release and autorelease during compile time.
1. You must check for leaks using Build and analyze in XCode, shift+command+b you should be clearing those issues.
2. After that you can start using the instruments by using profile option command+i . This will point you to where the leak might be.
This link will help you too http://soulwithmobiletechnology.blogspot.in/2011/04/how-to-check-memory-leaks-in-xcode-4.html
Edit: Added some screenshots to hopefully make it clear.
During profiling after selecting leaks choose the call tree option and check the boxes hide system libraries , invert call tree and show obj-c only as shown in image below.
After double clicking the symbol name below you'll get the line where it is leaking.
You'll get something like this.
Yes, even with ARC there are memory leaks. ARC is not a garbage collector, it only inserts for you, at compile time, retains, releases and autoreleases in key positions. So although it does help the developer, you should be aware that memory leaks still exist (for instance circular referencing). You can start by using the Static Analyzer and correct any problem it shows you. You can then go to Instruments and choose Leaks.

Stuck in memory leaks in my project

I am using UIImage picker, Local notification, event calendar, Date Picker , Facebook Sharing, Sounds, Navigation controller , database . My application is crash after some time, the reason is not same, Some times memory is full and some times too manny other receive memory warning. Please guide me how can i generally remove the leaks?
Have a look at this Cocoa Tutorial: Fixing Memory Leaks With Instruments. Instruments is the way to go to find leaks.
More resources:
Finding iPhone Memory Leaks: A “Leaks” Tool Tutorial
Apple's official Memory Usage Performance Guidelines / Finding Memory Leaks
Use Intstruments with the Leaks profile... see this article Leaks!
1.first of all release the objects in the dealloc .
2.Go to the xcode there in mainmenu you find the build tab.In that pressed on the build and analyze .It gives the errors.Remove those warnings.
If you are using autorelease objects, make sure it gets released at the right time. If you can,try not to use Interface Builder, i feel something is fishy abt it when it comes to memory.
Check the NSString objects, they can have devastating effects if not released on time.
also remember [UIImage imageNamed#"abc.png"] caches the images which also causes running low memory warnings.
Try to create your view hierarchy programmatically.

iPhone UITableView Leak

Any suggestions on how to work around this UITableView Leak?
Here's a link to a very basic test project that produces the problem:
http://www.maani.us/temp/Test.zip
To reproduce the leak:
Run the project with the "Leaks" performance tool.
In the table view, click '4' in the right-side Index to jump to section 4.
Scroll up a bit to display a couple of cells from section 3.
Wait for a few seconds. This generates a leak in the instrument.
I tested this both with version 4.2 and 4.3, both with the simulator and a device. All tests produce the leak.
Thank you for you help.
Are you testing this in the simulator or on the device? There are some known leaks with UITableViewControllers in the simulators that do not happen on hardware.
I ran this myself in my the simulator and the only leaks I am getting are for NSIndexPAth and generic 16 byte blocks, both of which are discussed on the internet as being leaked only on the simulator. You can also look at the leaks and see they are created and only accessed within the foundation framework. Therefore, it definitely seems to be a problem with the framework itself. One possible fix for this is to use a UIViewController and setup the UITableView yourself.
The test project above contains only the minimal code necessary to build a UITable and confirm that the leak is in the foundation framework (NSIndexPAth).
Yes, the leak happens on devices too.
The original code used a UIViewController that displayed a UITableView. That too produced a leak. I removed UIViewController to narrow down the problem and confirm that the leak still happens without too.
The only thing that removed the problem is removing the UITable section Index (sectionIndexTitlesForTableView:tableView), which is not a possible option in the final App.

Adding AdBannerView to application creates memory leak

I have a working iPhone app using SDK 4.0. It shows no leaks in the 'Instruments' tool, and I am fairly convinced that the code does not have any memory leaks.
I then tried to add iAds to the app, and it started showing memory leaks. In order to nail down the problem, I removed all additional code.
All that is left is an added AdBannerView to the .xib file (without doing a single modification to the working version of the code without iAds). This shows memory leaks.
Every time the view loads, the 'Instruments' tool shows 5 leaked blocks of 16 bytes each, with the Responsible Library 'Foundation', and Responsible frame
[NSCFString copywithZone:]
Further running the app gives me leaks from the Responsible library 'iAd' (2 leaks of 48 bytes each), and the responsible frame:
[AdBrandingFrame initWithFrame:]
Further, I also get 48 byte leaks with the responsible library 'UIKit' and responsible frame
-[UIView _createLayerWithFrame:]
Since there is absolutely no addition to my working non-leaking code, except an added AdBannerView to the .xib file, I wonder if it is Apple's code that causes the leak. Although the leak is relatively small, I would like to iron it out. I understand that there is a possibility that a leak shows up even though there may not be one (the pointers might still be held by the OS in some way that Leaks does not know about - It would be great to know if this is the case).
So I had two questions:
1) Is there any chance the problem is actually my code, and the leak for some reason only shows up after adding AdBannerView? If there is such a possibility, I would run another thorough code test.
2) If this is a problem with Apple's code and any of you have encountered this, are there any workarounds you have found?
Any help would be greatly appreciated. Thanks!
I just had the same issue. I think this has been fixed in IOS 4.1
When I test in 4.0 I got a couple leaks "NSCFString copyWithZone"
When testing in 4.1 all is good.

Iphone SDK Utility Application template has leak

i'm only create an project with a Utility Application template.
This template has a native memory leak when i push "info button" to
flip the view.
Anyone know how can i fix this leak ???
I just make an new project from this template,
i don't add new objects.
That might be a leak or it might not be a leak. If you were to add the backtrace of the allocation, that would be helpful.
More likely than not, it isn't a leak, but some bookkeeping information that is being stashed away by dyld that leaks/Instruments loses track of.
Given that it is 128 bytes and I'm guessing there is only one of them, I would encourage you to file a bug via http://bugreport.apple.com and then forget about it for now as, in the unlikely case that it really is a leak, you will be equally as unlikely to be able to fix it from within your application.
Hope this helps.
From: http://www.cocos2d-iphone.org/forum/topic/2460
"The simulator has bugs related to singletons and llvm stuff that are incorrectly reported by Instruments. Always check your leaks on the device itself."
Got the leak doing this:
XCode 3.2--
File, New Project, Navigation-based Application
Give it a name
Build It
Run With Performance Tools -> Leaks
When Instruments comes up, click on Leaks (you might have to click the little icon at the bottom that looks like four boxes within a box)
About 7 seconds after running you should see the leak:
-- Malloc 128 Bytes, some Address, 128 Bytes, CoreGraphics, open_handle_to_dylib_path
I traced it to this code in the AppDelegate:
//APPLE CODE
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after app launch
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
}
I broke out the navigationController (did a separate alloc and release) and COMMENTED OUT the addSubview: action - there was no leak - and, obviously, the screen was blank.
It wasn't until I attempted addSubview that the leak occurred. Since there are numerous ways to add a subview, I tried those. Each resulted in the leak or a blank screen.
I tried it on a real ipod touch. No leak was reported.
Probably just a simulator thing ...
Leaks has flagged open_handle_to_dylib_path in CoreGraphics for me as well; there is definitely something flagged here. Since it is merely 256 bytes at its heaviest, I fired off a bug report to Apple and called it done. You can then set a rule in Leaks' configuration to ignore the report.
As bbum pointed out, there might be serious voodoo at work. I seriously doubt Apple would let leaky frameworks go through QA -- especially since it's so easy to reproduce.
This must be a bug. It appears in Apple's own example, PageControl, found here:
http://developer.apple.com/iphone/library/samplecode/PageControl/index.html#//apple_ref/doc/uid/DTS40007795
In the current SDK utility template is no leak. How did you get the impression there's a leak in the template? It's just allocating memory which is needed for the views.
A leak is memory to which no pointers exist and which cannot be freed any more.
I had the same problem, but was able to understand why it happened. And I have given a brief info regarding this problem in this article
Might be useful for you.