Memory not released when storyboard disappear - swift

In my app there is a Login.storyboard and Dashboard.storyboard. Once I tap login button I am presenting Dashboard. When I tap logout button, all I do is perform unwind segue to Login. My DashBoard.storyboard disappear, but my memory allocations still are the same. When I login again, I allocate a new objects, when I logout, nothing changes. Doing just two things (login (present storyboard), logout (unwind)) I only increase allocations, instead of decreasing it while logging out.
How to fix this? Is it normal?

In my app there is a Login.storyboard and Dashboard.storyboard.
If literally true, that's your problem. You don't need two storyboards here - just one storyboard with two view controllers (scenes). If you're going to use two storyboards, then you just have to live with the extra memory usage that this entails.

Related

UICollectionView not release memory after select a new button

I'm working on a note app that has a collection view of notes, and taping each cell will lead the user to different note. In the case of my app, each note is essentially a PKCavnasView that inherent from ScrollView.
What I found is that when user navigate back to collection view and select a new cell, the memory used by the previous note is not released. So as user navigate between different notes, the memory usage will soar up.
What's more of a problem is that when the app goes to the background, all the memory is still not released.
What I'm wondering is that, will the navigation controller automatically release the memory of each tap to different cell? If not, is the autorelease pool the solution here? If so, where should I put the autorelease pool.

UINavigationButton & UIButton on PopToRootViewController?

My app has a sign in button and a sign up button, which are UINavigationButtons and UIButtons respectively. Either segues to a new screen that, on success, should PopToRootViewController; However, when I successfully sign in, my sign in and sign up buttons are still present. I have a method that decides whether or not to display the buttons that gets called in the viewDidLoad method. Thus, when I stop/run the app again, the buttons disappear as they should. Can anyone give me advise on how to get these buttons to hide? Thank you.
Bonus points: I also have a log out button that has a similar issue; I have to re-run the app before my view controller realizes it should hide the logout button and show the sign in/up buttons.
The problem is that viewDidLoad is only called once, so it is hardly suitable for this purpose; it has to do with the view coming into existence, and nothing to do with the interface. Use viewWillAppear: and make the decision about whether to show or hide the buttons on the basis of, say some info you've stored in NSUserDefaults (like, has the user signed in or not).

How to release entire UINavigationController

I have an iPhone application, and I have included a virtual "timeout" for being in the background. When it enters the background, I make a timestamp. When it re-enters, i compare the current time to the timestamp. This all works great.
What I want is for the application to basically reset like it was just launched. Everything in my application lives inside of a UINavigationController, so I thought I could just release it and everything inside, then reallocate it and start over. Is there a right way to do this? I have a feeling that if i just "release" the UINavigationController, all of the ViewControllers inside will just leak into memory.
You can just release your UINavigationController, and if your ViewControllers are only retained by your UINavigationController, which should be the case, then they will also get deallocated.
You may reset your model data manually and then return to start screen of your app by
[self.navigationController popToRootViewControllerAnimated:NO];
To do this in a sensible way you need to reset your controllers and data model to the state you want (e.g. as if your app was just launched). I'd also do this in a way that looks natural for your users. Something like the following:
Load a splash screen view (or something temporary) in the main app window.
Release your navigation controller (more generally, release the top level controller owning the view previously added to the window). this will release all associated controllers and views assuming you haven't retained them anywhere else.
You may also need to handle any modal views that were displayed when your app went into the background. You can either dismiss them automatically when the app goes into the background or keep state around to dismiss them when the app resumes and you are resetting it).
Reset your data model to the state you want
Recreate your navigation controller and add it back to the window and release the temporary splash screen.

Reloading subviews of UINavigationController

I'm kind of new to iPhone development so bear with me.
I have an application wherein I display a lot of data in a tableviews, edit it in a detailview etc. However, I also have a login-system.
The problem I have is that I can't figure out how to reload the subviews of the NavigationController when I've logged out, or how to dealloc it completely and reinitialize it upon a succesful login.
This means that data from the last user who logged out is still present in my tableview when I log in as another user, as the data is set to reload only when the view loads for the first time.
Thankful for any and all contributions.
There are probably several ways you could go about this; it's up to you (and without more information about your app, I can't suggest a particular solution). You might consider:
-viewWillAppear: — this method is called on any UIViewController subclass when it's about to (re)appear as part of a UINavigationController stack (or tab bar controller, etc.). You can clear out fields, etc. This is mostly useful when a view controller reappears (being uncovered or switched to), because you usually create a new view controller instance each time you display one.
Notifications and delegates — your view controllers (and other objects) can communicate with each other about when a logout occurs, and reconfigure themselves as necessary.

why would I sometimes lose Navigation items when clicking to return to previous screen in UINavigationController app?

Anyone know why would I sometimes lose Navigation items when clicking to return to previous screen in UINavigationController app?
Background:
have a iPhone app using a UINavigationController and UITableViews
98% of the time things are fine, and if I'm on the detailed screen and click the "back" button things are find. The app takes you back to the main screen (pop's a view off the stack)
a small percentage of the time, and on the iPhone device itself, I click to go back, see some animation start, but I end up (a) on the same page, and (b) no navigation buttons or toolbar buttons appearing
from this state you can't do anything obviously and have to kill the app and re-start
Any ideas? How to fault find? (noting it's only occasionally when testing on an actual device I notice, and it may take hours/days before it does occur)
thanks
Add an alert in didReceiveMemoryWarning function of the viewController. The OS calls viewDidUnload on some memory warning (which don't usually happen in simulator).