George Termentzoglou
George Termentzoglou

Reputation: 95

uinavigation controller stack memory management

I have created a navigationcontroller where a view controller might be pushed multiple times ..for example if we say that we have created a ViewController with memory position <x1234> and I add it once at index 5 once at index 7...what about memory?Will it crash after a while or will there be no problem because Im always using the same object?

Upvotes: 1

Views: 220

Answers (2)

Stephen Darlington
Stephen Darlington

Reputation: 52575

You can't push exactly the same object onto the navigation controller stack more than once:

Important In iOS 2.2 and later, if the object in the viewController parameter is already on the navigation stack, this method throws an exception. In earlier versions of iOS, the method simply does nothing.

But you can push different instances of the same view controller.

iOS will send memory warnings (where you can clear out any temporary storage that you can re-create) and will unload any views that are not visible. This means that the overhead of a new view controller is relatively small but non-zero. There is a limit beyond which you'll get problems, but in practice, as long as you correctly obey the memory management rules, it's pretty high. Certainly higher than the limits imposed by making a usable UI.

Upvotes: 1

beryllium
beryllium

Reputation: 29767

You cann't add one view controller several times into one stack. But you can create multiple instances (they will have different memory position) and push them into navigation stack. Of course, if you will create >1000 instances then your app will crash. In fact, stack usually contains 1-10 view controllers and all works fine.

Upvotes: 0

Related Questions