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.
Related
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.
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.
Dear all, I have a navigation-based app with about 60 UIControllerViews, which is divided into 4 sections.
I have run with the following : 1. Build and analyse : bulid is successful with no complains. 2. Instruments allocation and leaks : no leaks.
However, the app crashed in iPhone or iPad but works fine in simulator. There is no crash reports but I do see LowMemory.log in the crashreporter folder.
I have upgraded my iphone and ipad to 4.2
Does anyone have ideas what could be wrong? I have been reading and troubleshooting for a week.
Is there a need to remove/release the UIControllerViews?
The app crashes simply by navigating between the views.
Thank you for any help.
My app has a root view called contentViewController and users can navigate to 4 quizzes from here.
This is the code I use to return to my root view.
- (void)goHome {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: #"Warning"
message: #"Proceed?"
delegate: self
cancelButtonTitle:#"Yes"
otherButtonTitles:#"No",nil];
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
[[self navigationController] setNavigationBarHidden:NO animated:YES];
if (buttonIndex == 0) {
NSArray * subviews = [self.view subviews];
[subviews makeObjectsPerformSelector:#selector(removeFromSuperview)];
self.view = nil;
if (self.contentViewController == nil)
{
ContentViewController *aViewController = [[ContentViewController alloc]
initWithNibName:#"ContentViewController" bundle:[NSBundle mainBundle]];
self.contentViewController = aViewController;
[aViewController release];
}
[self.navigationController pushViewController:self.contentViewController animated:YES];
}
else {
}
}
The simulator isn't going to give you any useful information about memory warnings—your app, running there, effectively has access to all the memory the system's willing to give it. The device is where you need to be testing for memory usage, and if you're getting warnings and crashes, then you need to do some Instruments work to figure out where you can free up some of that memory.
Look at your xcode console. If you are getting a number of low memory warnings, then you need to be allocating and de-allocating your views on the fly because they are taking up too much memory on the device (the simulator isn't quite so memory restricted).
But it could be about a million other things causing your crash. Make sure you're doing a debug build (breakpoints on) so the debugger will kick in and hopefully you can see where on the stack your crash is occurring.
You have some good suggestions already. However I'd suggest spending a lot of time reviewing XCode's debugging tools documentation. This so you have a basic understanding of what they are capable of and how to use them. Follow that up with some reading on iOS memory management, auto release pools and the like.
For your app you need to realize that there is no swap space on iOS devices. So you are forced to manage memory to an extent that you mat not have to on other platforms. Generally that means you don't want to keep to much view data in memory if it can be avoided.
In the case of the current iPad there may only be about 110MB of RAM available to the app. Specific numbers probably are iOS version dependent. In any event you need to get an idea as to how large the data structures (in memory) are for your various views. 60 different views could be considered a lot depending upon memory usage, if you don't manage it correctly you are likely to run out very quickly. This not like programming in Java or other garbage collected language.
Lastly; even though this sounds like a memory management issue it could always be something else. If you still have trouble you will need to post code. Right now it is really guess work on our part. Just remember you do not have VM and there is no garbage collection.
You are using up memory, always remember if you allocate memory you must release it, in some cases you can use autorelease so you dont forget to release it after the void dealloc method before end.
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!