push and pop controller slow response - ios

I have 3 controllers. I am using push and pop method to change the controllers.
[self.navigationController pushViewController:product_subcatagory animated:YES];
[self.navigationController popViewControllerAnimated:YES];
The issue I am getting while i am continue doing push and pop operation for 8 to 10 minutes as it responding slow animation and at one step is getting crashed. So what could be the reason for slow animation for push-pop controller operation.
Below as Example I have 3 class A,B,C. Then following push view controller and pop view controller operation i am performing.
A->B->C It has three possibilities 1. B->A 2.C->B->A 3.C->B
Thanks in Advance.

Profile your app using Instruments. One possible reason is that your app is not releasing memory (due to retain cycles), and is slowing down and crashing because its memory usage keeps growing and growing.

I agree with Petah. Sounds like a memory issue. You might want to consider actually removing them temporary and calling them back as needed so they're not just sitting in the background using unneeded memory.

Related

Size of memory usage of IOS App

I have created an app with 12 view controllers and its got a lot of graphics ( image files )
When I launch the app, I notice the memory goes up as I move through the view controllers.. once I have moved through all the controllers the memory is 530Mb
so my questions are :-
a) is this a lot of memory to be using
b) should I be worried
c) how can I remove view controllers from memory as I navigate round.. for example I have a view controller for on boarding , but once some clicks on skip or get started, I segue to the next view controller, so in theory it doesn't need to be loaded any more..
Thoughts ?
Im running on an iPhone 7 Plus which has 3Gbm, but want to be able to run the app on other phone models from iPhone SE onwards. however I notice the memory profile is about 50% no the iPhone SE but assume thats because its not loading the x3 images as per plus phone
a) is this a lot of memory to be using
lot is a relative term and whether 530Mb is lot or not completely depends on what app is doing and what kind of app it is! If its a game with rich graphics I wouldn't be bothered much but if its a plain utility app I would be concerned!
b) should I be worried
Memory getting accumulated/increasing as user loads various screens of app is a very common scenario. You should be bothered if it keeps increasing and never comes down. Every time a VC loads it might load, heavy graphics with it or might allocate large amount of variables and consume lots of memory to perform its function. Which is quite fair. But once user pops the VC from applications navigation stack all the memory allocated by the VC should be returned and total memory consumed by the app should come down. Ideal memory foot print would look like a wave where it reaches peak and comes down once VC pops out. If thats not happening you are in trouble :)
c) how can I remove view controllers from memory as I navigate round
Use proper navigation techniques. Don't keep pushing the VC's to navigation controller stack unless you actually need that VC instance to be retained in memory. All VC's pushed to Navigation stack will continue to be kept in the memory till either user kills the app or iOS decides to kill the app on receiving memory warnings.
Write deinit/dealloc in each VC and make sure it gets called every time user pops the VC by either tapping back button if its pushed or by dismissing VC if its presented modally. Ensuring each VC's deinit gets called is the best way to ensure VC does not hold up any unnecessary memory.
Make sure none of your VC has code which results in retain cycle and retains the objects in memory forever. Example : If your VC declares a block and holds the strong reference to block and if you pass self to block your block and self will never be released. Classic example of retain cycle. Make sure your code does not create such dead locks
Never hold anything strongly by using either strong/retain unless its necessary.
Use instrument to find the memory leaks and reference counts of each objects just to make sure there is no memory leaks in ur app.

In ARC,dealloc is called but memory still increasing

In viewController A , I have a custom button, and click it will push to viewController B. And then I pop to A from B, the dealloc method in B is called to log something. Repeatly doing the push and pop actions again and again. Every pop action will release the memory but less the increase of the push action. So the memory is accumulatly increasing . I notice that from the xcode7 debug navigator. After 20 minus test, the memory increse from 30M to 118M, is it normal? Dealloc method is called means what? Is there a memory leak or exist abandoned memory? Thanks for every ideas.
Edit:
I upload a screenshot from instrument. Thanks for your tips.

background methods are not stopping after viewWillDisappear/ Dealloc

First of all Check This to understand what i am doing
I did not get my answer in above question & still waiting for it.
Now new porblem is that when i click on back button using following code, methods of last ViewController are still running. It will use memory & keep processing untill it gets response(that`s what i want to do but if user press back then i want to stop all methods)
[self.navigationController popViewControllerAnimated:YES];
How do i stop it?
You need to do [getTryAgainTask cancel] (assuming getTryAgainTask is of type NSURLSessionDownloadTask) before you pop this controller. The download task is asynchronous and runs irrespective of the controller (that fired it) being deallocated. This might cause retain loops, leading the app to eventually crash. The code as of now, will go into an infinite loop. A better solution would be to keep a tab on the number of retries (say 3 times) and then prompt the user about the problem, asking if he/she would like to try again.

Monotouch memory view controller problems

I have a problem with the memory consumption of my app I hope you can help me with this, I have a Navigation Controller with maybe 10 controllers to navigate forward or backward, I'm using Instruments to check for the memory allocations (also used the mtouch profiler), when I navigate forward (1st time) obviously the memory consumed by the app increases .. but when i click on the standard back button of the nav controller the memory stills being the same amount and worst of all if I go forward again the memory increases more (i.e.: homeVC 10mb, VC1 = 10.5mb, back to homeVC = 10.5 mb, forward to VC1 = 11mb), yes the memory is increasing while I still navigating through the VCs. In this scenario I have the following questions:
What is the behavior of the app on the standard Back button of the nav controller (it executes a PopViewControllerAnimated?).
PopViewControllerAnimated and the other Pop methods of the navController should release the memory consumed by the dissapearing VC?
If the Pop methods of the navcontrollers don't release the memory of the app, when I should dispose my disappearing VCs to avoid consuming so much memory? (I want to know the best work of manage the memory in the mono touch apps, maybe use the DidReceiveMemoryWarning method? or there are another places when i can manage the release of the memory of my app).
Thanks in advance for all your help.
This sounds suspiciously similar to this bug: https://bugzilla.xamarin.com/show_bug.cgi?id=1889
You can work around it by fetching the ViewControllers property of the navigation controller once in a while.
Can you post the code you use when you allocate and push your VC?
What I'm guessing is happening is you aren't releasing it after you allocate it, so when the NavigationController releases it when you press the Back button the retain count is still +1.

Memory warnings in IPAD app with UITabbar of 8viewControllers

My application which is a UITabbar app has eight tabs. one tab for playing Audio, one for Playing Videos, one for Books(Leavesview is used for opening jpg image pages),one for Gallery.....so on.
So, Once I open all tabs the app throws memory warnings and crashes.
Then I did this: In each tabs viewController, I have allocated everything(views, imageViews.....) in ViewDidAppear method then I did removeFromSuperView and release in ViewDidDisappear method.Even then the problem persists.
Using Activity Monitor I observed that the app crashes when it exceeds 128 MB of Memory.
Each tab's ViewController is Occupying around 40MB memory. Even though I release everything in the ViewDidDisapper of the tab the memory is not freed but kept on increasing.
Is there anything regarding memory I have missed. Please Help me resolve this , Thank You.
I have noticed that when instantiating a UITabBarController it loads all it's dependencies and is really stubborn when trying to release an entire UIViewController. I've done a few things to combat this when I've had high memory UIViewControllers attached to a UITabBarController. What I suggest is only releasing the memory hog controls associated with each UIViewController on the ViewWillDisappear and re-Instantiating them on the ViewWillAppear rather than trying to release the entire UIViewController. Typically this is bad practice because you want to recycle as many of the controls as possible but if you have to stick with the UITabBarController this is the only way I've been successful.
If I misread your post and you aren't trying to release the UIViewController the I would need to see some code to figure out why things aren' releasing on ViewWillDisappear.

Resources