iOS App is getting slower after dismissing ModalViewController - ios

I'm developing an iOS App which has to do much work on a Modal VC. (Images, etc).
This leads to a lot of allocated Memory. Which is okay while presenting the view.
But after dismissing the View I'm still having that Memory allocated.
In the simulator I can free some Memory by sending a memory warning.
The problem is that my App runs slower after dismissing the view.
I'm doing some fade and move animations after that and it is significantly slower than before.
I'm using ARC and developing for iOS 6/7.
Do you have any ideas how to free the memory programmatically?

Found the problem...
I had still a reference to the Modal View in my View Controller which presented the Modal View.
But I still have the same Problem. My App runs slower after presenting the Moadl View.
Although I don't have much memory allocated.

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.

Memory optimization ios app, On Pushing app to background minimizing the app runtime memroy size

I am developing big iOS app. Here I am using lots of animations in each view controller, and due to that some times app crashes due to memory.
Issue is described Below
Pushing View Controller, where on Tapping the button, start UIImage animation with 10 images. Which increase the app memory usage from 13MB to 53MB(Checking in "Debug Navigator" of Xcode 8.1 and iPhone 5 with iOS 10.1).
When Poping the View Controller it is not decrease the memory size.
But if I send the app to background at the same moment then it dramatically decreasing the memory to 17MB.
Can you please guide me regarding this, how I need to handle this situation.
Note:
- Both Objects (ViewController and Image Object) calling its dealloc method, So means they should free the memory.
- I even tried #autorelease pool, but not helpful.
Thanks In Advance
might be you didn't sop this animation, on viewWillDisappear try to call
stopAnimating (in case you are using UIImageView for frame animation).

Main View gets dark when coming back from Background

I am using RouteMe's library and services to display maps.
The main ViewController holds an *RMMapView that inherits from UIView. Basically it just fills up with tiles.
When my app goes to background, and after a while, after other apps are loaded into memory usually, comes back to foreground, The main mapView goes completely black and I can't see anything except for my UI.
(I guess due to lack of memory)
How can I prevent that from happening ?
Thanks!
you cant prevent a Memory warning from happening, however if you are 100% sure that you cant handle the memory warning in some view controller and to stop the call to viewDidUnload remove the implementation of didReceiveMemoryWarning in your view controller
Please note that disabling the viewDidUnload is not recommended, you should reflect about your memory usage and present a better memory management technique

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