NSAutoReleasePool Leaks on allocWithZone - iphone

So this has been confusing me for a while. I am running my app in the "Profile" Mode trying to find memory leaks in my app. I think I got all of them expect when I click on the Map part of my application it reports back that a reference to NSAutoreleasePool was leaked from the Foundation Library. I check the trace of the object but it only reports back from the method allocWithZone. It seems to leak only once on matter how many times I alloc and dealloc that view controller. I did a search of my code and the only reference I make to NSAutoreleasePool is in the main.m file. Is this an Apple bug (which I doubt) or am I doing something wrong?
main.m
#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;
}

Looks like it was an Apple bug. The same amount of memory is leaked in the other question which leads me to believe they are the same bug. I did an extensive code audit and nothing seemed to be working to get rid of the leak. Oh well I hope they fix it soon. NSAutoReleasePool Leaks on allocWithZone

Related

Create calendar event from inside my application

I know that there already are lots of questions and even useful answers concerning this question on the web. I tried to add a calendar event to the iPhone calendar from inside my application. I used this code, which actually worked:
EKEventStore *es = [[EKEventStore alloc] init];
EKEventEditViewController *controller = [[EKEventEditViewController alloc] init];
controller.eventStore = es;
controller.editViewDelegate = self;
[self presentModalViewController:controller animated:YES];
The only thing was that I could not release the calendar controller, which is because I should have said:
[Controller release]
or something
But my main.m is set to autorelease:
int main(int argc, char *argv[])
{
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([...AppDelegate class]));
}
}
and if I manually release I get an error, do I have to change something in the main.m?
In your target's build settings, if you see Objective-C Automatic Reference Counting then you are using ARC:
And if you are using ARC then you are not responsible to release object by your self.
I strongly recommend to read more about ARC, you can start from here, this is the most important thing you should consider if you want to build a real application.
As I understand from the comments, it might be you are using ARC. In order to check that, go on your project tab, select Build Settings and type in the search bar
Automatic Reference Counting
If it's set to you YES, you don't need to release the object.
EDIT
It looks like there have been a misunderstanding regarding the word release. Release as you mentioned it (calling release on an object) means to decrease the object reference counter.
Dismissing a modal view controller is a complete different thing. In order to do that,
on the cancel button delegate method, you have to invoke:
[yourViewControllerInstance dismissModalViewControllerAnimated:YES];
That's the method you are searching for.

how to use auto-release in iphone

I want to use the auto-release in my apps. I want to implement this methods
- (void)selectorConnect: (NSArray *)args
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
//some code
[pool release];
}
Getting crash at [pool release] line. Any solution for that .
When you empty an autorelease pool, it calls autorelease on all objects inside it.
If you're getting a crash with the [pool release] line then you've added an object to the autorelease pool and have released it yourself.
Run the static analyser and see what warnings it gives you.
And if you still don't know, enable NSZombies and see what object is being released twice.
Finally, if that still doesn't help, add your code to the question and we can all take a look :)

Sometimes my project works fine, sometimes it shows following error in the line mentioned in the code below

#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);//Program received signal: EXC_BAD_Access"
[pool release];
return retVal;
}
You’re accessing bad memory somewhere. Most probably, you're trying to reference a pointer to an object that's been released already, and the debugger has had to roll back to the bottom of the stack. Usually, a hint to the real reason for a crash like this will appear just slightly before "Program received signal: EXC_BAD_Access" in the log.
Good luck.
EXC_BAD_Access means you're overreleasing an object. Run the app using Instruments Object Alloc with Zombie detection enabled to find the culprit.
Your application going to crash that's why you are getting error at this point,
you can check where application going to crash by selecting iOs Simulator 4.3 and lower version.
This may help you to debug the problem.
iOS 5.0 and later never tell where is the issue for that you must have to run you app in lower version then 5.0.

iPhone SDK "clear" function not working-button

I have a question relating to a button I made for my app. I am fairly new to iPhone development so please stay with me. When the "clear" button is clicked, it is programmed to reset the text fields. The other "calculate" function works fine. The app runs perfectly until I press "clear". Then the app will completely freeze. The following is displayed in Xcode.The commented out is the error I get, I think it is some sort of breaker:
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
//Above error reads "Thread 1: Program received signal: "SIGABRT"
[pool release];
return retVal;
}
I feel like this is a simple mistake but I am unfamiliar with mobile development and just started it. Any help would be greatly appreciated!!
When this occurs, it usually means Xcode couldn't figure out where something went wrong. The best thing to do is to set a breakpoint in the first line of your -clearButtonWasPushed: method (or equivalent). Run it step by step, and then when it crashes to your main.m code, you'll know which line caused it. You might have overreleased something by mistake...
Alternatively, UITextField has a built in clear button, which you can activate programatically or in IB:
textField.clearButtonMode = UITextFieldViewModeWhileEditing;

Memory leaks in an iPhone app

I have the following memory leaks in my code. What does it mean? How can I fix this?
#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;
}
Thanks in Advance.
That code is from your main.m file. It seems odd that this part of your code would leak, if at all??
How did you find this leak?
Are you using the simulator or a real device?
If using the simulator you can sometimes have leaks that are not leaks at all, it is always better to test these kinds of things on a real device (which you have not specified). Double check all of your release, retains etc in your code. You might just spot something you have not released. (in xcode 4 use the assistant editor I find it better to spot these kinds of things alt+cmd+enter).
Your question otherwise is hard to answer, you might want to edit it with how you found it and in what environment.
Hope some of this helps
[EDIT] saw you tagged this with cocos2D (what version are you using of that?) there are some reported issues elsewhere on SO with memory leaks using older versions of cocos2D