Monotouch memory view controller problems - ios

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.

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.

push and pop controller slow response

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.

iOS App is getting slower after dismissing ModalViewController

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.

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.

Memory issues in releasing a UIViewController with UITextField

I've some memory issues with a view controller that contains a text field.
Brief summary:
Clicking on a button my application modally presents a UIViewController (that I will call "VC1").
From VC1 the user can optionally open (using pushViewController) a UITableViewController ("VC2") and turn back.
From VC1 the user can optionally open (using pushViewController) a UIViewController ("VC3") and turn back.
Finally the user can dismiss VC1
VC2 and VC2 are referenced in VC1 as properties and they have to remain in memory. When the user dismisses VC1 then I release all.
VC3 contains a simple view with only one UITextField that becomeFirstResponder when viewWillAppear is invoked.
Issues:
When I open VC1 and then VC2, turn back and dismiss: it's all ok, the application returns to the same initial amount of "Live bytes" (that is 1,20MB). When I open VC1 and then VC3, bytes become 2MB. When I write something inside the text field allocations rise to 2,50MB
In this moment Instruments discovers a memory leak of 16byte with ProofReader as Responsible Library and PRRfInit as Responsible Caller
After turning back to VC1 and dismissing, the allocations remain to 2,50MB
Ordering by category in Instruments I checked that VC1, VC2 and VC3 have 0 live bytes, but the overall remains to 2,50MB
Is also involved the keyboard?
I'm assuming that you're testing on the device, not the simulator - the simulator produces incorrect results.
The total memory used by your app is fairly meaningless as a measure of memory leaks - the iPhone will try to cache as much data as it can while there is free memory - it will load libraries and leave them in memory in case you are going to use them again. It's only an issue when you start to run out and then it will sort it out for you.
And a 16byte leak from a library is fairly irrelevent (assuming it only happens once) - Apple's libraries end up leaking more than that in my experience.
There are many better ways to spend your time ;)
PS Is ProofReader a library you have included or one that's part of Apple's SDK?

Resources