I am doing memory leak testing. The tool indicates a leak in line 2 of the code below. What is the reason?
DailySales *ds = [[DailySales alloc] initWithNibName:#"DailySales" bundle:nil];
[self.navigationController pushViewController:ds animated:YES];
[ds release];
The code looks fine. Are you running in the simulator or on the device? Running Instruments on the simulator can produce false leak reports.
Objects loaded from the NIB are leaking. Check your outlets and see if they are carefully released in dealloc.
Related
My application crashes when I navigate to different view for more than 10 to 11 times. I mean I have 6 buttons on main screen which on pressing bring you to different views. when I press these buttons repeatedly then my app crashes. I have spent 3 days but comes up with no solution. here is the code where app crashes
when i uncomment release statement then it crashes after first time.
-(IBAction) goToLiveAlerts{
teamAlerts *showLiveAlerts=[[teamAlerts alloc] initWithNibName:#"teamAlerts" bundle:nil];
[self.navigationController pushViewController:showLiveAlerts animated:YES];
//[showLiveAlerts release];
}
when i uncomment then i console error is
"wait_fences: failed to receive reply: 10004003
[Switching to process 2093]
[Switching to process 2093]
Program received signal: “EXC_BAD_ACCESS”."
-(IBAction)goToPhotos{
picturesGallery *showPictures=[[picturesGallery alloc] initWithNibName:#"picturesGallery" bundle:nil];
[self.navigationController pushViewController:showPictures animated:YES];
//[showPictures release];
}
Do you use ARC or not? If not, according to your code, there is some memory leaks in your code, try this:
-(IBAction)goToPhotos{
picturesGallery *showPictures=[[picturesGallery alloc] initWithNibName:#"picturesGallery" bundle:nil];
[self.navigationController pushViewController:showPictures animated:YES];
[showPictures release];
}
Anyway, you need to provide more code crash log.
According to your crash log, EXC_BAD_ACCESS means there is some memory leaks. Enable NSZombie in Xcode to debug. In Xcode 4.3, go to Product->Edit Scheme->Diagnostics and check Enable Zombie Objects.
Instruments show me a leak in simulator in the following code,
UIBarButtonItem *connectButton = [[UIBarButtonItem alloc] initWithTitle:#"Connexion" style:UIBarButtonItemStyleBordered target:self action:#selector(pushViewController)];
[self.navigationItem setLeftBarButtonItem:connectButton animated:animated];
[connectButton release];
Do you see any leak ?? thanks
Leaks is showing you where the object was allocated, not where the object was leaked.
While the two might be the same, it is often much more likely that the leak of an object is caused by an extra retain or missing release somewhere else.
I don't see any leaks in the code you posted. That said, a couple questions:
How do you know that's where the leak is?
Any chance the getter for navigationItem is using copy? If so, there could be a leak there.
...and on device? You should check this on device. There are very, very few situations where you'd want to use the simulator for this kind of testing. It's not representative of how the device itself behaves. I'd recommend you test this on a device, and then if you're still seeing it come back here.
i have found leaks in the below code at particular area, means when i push my view from other sides, There is not any leak i found but only this push give me 100%leak.
actionsListing *View = [[actionsListing alloc] init];
[self.navigationController pushViewController:View animated:YES];
[View release];
What will i do thanks.
That code is fine - you're doing everything correctly.
Are you testing in the simulator or on a device? If it's the simualtor, don't. The simulator has a different memory model and reports leaks that aren't really there; always test for leaks on a device :)
If you still get leaks, you're retaining the view controller somewhere else by mistake - that code is definitely correct.
I am having problem finding a memory leak with Instruments. Usually it helps me a lot and I am able to find the leak, but in this case I'm lost.
I am creating a view controller that controls a views loaded from NIB file. The view has Map View with "Show user location" on true. Once user location is found I use MKReverseGeocoder to get the location data. The leak is always present when I load this view controller and MapKit finds user location. I figured out that MKReverseGeocoder isn't problem here, since I get the same leak with or without the MKReverseGeocoder.
When I load this view Instruments "leaks" report a memory leak. See the screenshot on the image:
This is how I initialize my controller:
AddPlaceViewController *addPlaceVC = [[AddPlaceViewController alloc] initWithNibName:#"AddPlaceViewController" bundle:[NSBundle mainBundle]];
addPlaceVC.delegate = self;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addPlaceVC];
self.placeController = navigationController;
[self presentModalViewController:self.placeController animated:YES];
[addPlaceVC release];
[navigationController release];
This is all on the iPhone Simulator 4 and targeted OS 3.2.
Is this actually leak or what I am facing here?
Since the responsible library is "Foundation" and not your code, there is nothing you can do about it (except report it to Apple).
uiimagepickerview controller creating memory leaks in iphone - why?
Try to implement ui image picker view controller in your application & debug it.
You will find memory leaks in your application.
Why ui image picker view controller creates memory leaks.
-(void)addPhotos:(id)sender
{
if(imagePickerController==nil){
imagePickerController=[[UIImagePickerController alloc]init];
imagePickerController.delegate=self;
imagePickerController.sourceType=UIImagePickerControllerSourceTypeSavedPhotosAlbum;
imagePickerController.allowsImageEditing=YES;
imagePickerController.navigationBar.barStyle=UIBarStyleBlackOpaque;
}
[self.navigationController presentModalViewController:imagePickerController animated:YES];
}
dealloc of my view controller.
- (void)dealloc {
if(PhotoDateArray!=nil)[PhotoDateArray release];
if(imagePickerController!=nil) [imagePickerController release];
if(objDetail!=nil) [objDetail release];
if(Picimage!=nil) [Picimage release];
if(mySavePhotoController!=nil) [mySavePhotoController release];
if(LoadingAlert!=nil);
[super dealloc];
}
Video link explaining how I am getting the memory leak in it..
http://www.yourfilelink.com/get.php?fid=508534
Even though you have the nil check, it's still possible to leak memory. I think what is happening here is that you are calling alloc / init multiple times, but only releasing once. My guess it that addPhoto: is wired up to some button click, dealloc would only be called once when the delegate is trying to destroy. This creates a situation like this:
button click
alloc / init
button click
alloc / init (memory leak on first alloc'd picker)
close window
dealloc (free second alloc'd picker)
A better way might be the way Apple does it in the PhotoLocations and iPhoneCoreDataRecipes examples:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
Then listen for the didFinishPickingImage and imagePickerControllerDidCancel messages to your delegate and a call to [self dismissModalViewControllerAnimated:YES]; in both places should suffice.
I dont know about the rest of the code, but do you ever have a release?
[imagePickerController release]
UIImagePickerController loads and initializes PhotoLibrary.framework the first time it is shown. This memory won't be reclaimed until your application is closed.
(the code you posted doesn't appear to have leaks as-is, but that doesn't mean it won't interact with the rest of your application in a way that causes them)
I can explain this because I was having the same problem.
Don't test memory on the simulator!
If you test the apple code on a device the memory problem disappears.
I was having a memory alloc leak which I found in Instruments. All I was doing was opening and closing the image picker (open/cancel) and using Apple code, my code and other people's code, just like yours above.
All were showing the allocation going up and up each time, as if the picker was not being released. If you tried to release it, it would crash (over released).
Then I found a really helpful web page which basically stated:
"This doesn't happen when testing on the device"
So I switched from the simulator and ran the tests on the device. Lo & behold there was no allocation increase and it behaved normally.
This however is totally evil and now we can place no trust in the simulator to do a reliable job.
I want to add this to save people, the time, pain and bewilderment of wondering wtf is going on!