iPhone: “Unrecognized Selector Sent to Instance” Error - iphone

I’m trying to implement a partial overlay modal in my app with the code from “Semi-Modal (Transparent) Dialogs on the iPhone” at ramin.firoozye.com. The overlay functionality works and it slides the modal into view, but calling any IBAction from the modal's controller causes an “Unrecognized Selector Sent to Instance” crash.
I recreated the basic functionality with that code isolated, and it triggers the same error. To see what I’m talking about, you can download the test project here.
I’m sure I’m just missing something simple here. Any help would be greatly appreciated.

When showing your ModalViewController in TestViewController displayModal:, you release your modalController (line 20). Don't do this - you need the ViewController to stay alive. If you release it, only the view keeps alive (as it is retained when added as a subview).
Also, in ModalViewController hideModalEnded you release modalView, which you didn't retain, so I'd remove that one as well.
So now you need to release just the instance of ModalViewController after the view got removed. You can do this by [self release]; in hideModalEnded, but this seems to be an unusual pattern and I don't feel good doing it.
Some suggestions:
Keep the show and hide methods in the
same class.
Keep an ivar around with the
controller.
Another possiblity: Remove the
ModalViewController altogether and
put everything in TestViewController - But this very much depends on how much action there will be going on in the real thing.

Related

Issue with view controller not releasing memory

I'm working on an app where different view controllers get pushed and dismissed via dismissModalViewControllerAnimated.
I'm having some memory issues with the app just crashing after a while. Looking at the Leaks instrument, I see that my overall allocations keeps going up and up. Even after the viewcontroller is dismissed, memory does not go down.
Are there any obvious reasons for this? What is the simplest and easiest way to find out why my app is crashing? Thanks
POSSIBLE SOLUTIONS
I went through some trial and error as well as googling and made a few changes:
1) A delegate relationship may have been retaining the viewController, so I changed the object's delegate property to weak.
2) NSTimer's should be invalidated before dismissing viewController.
3) UIView animations may interfere with dealloc being called? You can use [view.layer removeAllAnimations] to end them before popping your viewController.
If your memory is not go down after the dismissModalViewControllerAnimated .. it means you are creating the Global Object of the ViewController And after dismissing you are not setting the Object = nil;
If you set nil then your memory goes down automatically.

Modal View doesn't release itself after dismiss

I've been facing a weird issue with dismissing a modal view.
I present a modal view like this:
ResepiDetail *detail =(ResepiDetail*)[[ResepiDetail alloc]init];
[self presentModalViewController:detail animated:YES];
and dismiss it like this with a back button:
[self dismissModalViewControllerAnimated:YES];
after this the view dismisses itself and goes back to the previous view, but it doesn't release itself from memory. I found it out by sending a notification message and that view received it. Additionally I tried to track the VM memory Allocation, and it seems the view is still in memory.
I'm using ARC and have the same method used for another view which works perfectly.
The code is fine, as posted, so here's some hints on how to proceed:
A sure fire way to be certain your view controller hasn't been deallocated is to override dealloc and log something identifiable. You can still do that in ARC, just don't explicitly call super. If you don't see the log when you expect to, then you have a problem.
Assuming that you have determined that you absolutely do have a problem, then the issue becomes finding the retain cycle. If the issue is that an instance of ResepiController isn't being dealloc'd, then you need to look for...
Any code outside the ResepiController class that has a strong reference to it. For example, if your class signs up as the delegate of some other class, make sure the delegate isn't using a strong reference.
Any internal blocks that may have implicitly retained self. Are there any blocks anywhere in your program that may have a reference to your controller at the time that you think it should be released?

Parent ViewController deallocated upon memory warning

I have a MainViewController, from which a new VideoPageViewController is presented modally.
In the ViewPageViewController, it will load a web page and launch the video, which is a heavy operation and sometimes causes memory warning. When it is ready to return to the MainViewController by dismissModalViewController, it says the MainViewController is already deallocated! The app thus crashes.
This happens sometimes, but not always.
Is there any exception handling I can take on it? Can I recreate the parent view controller? HELP!
Thanks
Just retain the MainViewController so it's not released when that happens.
You can probably do that in your application delegate, or in the class that owns it.
Remember to release it when/if you are done using it, so it's properly disposed of.

how to know whether dealloc is getting called or not in iphone sdk?

i am using UIviewcontroller subclasses. In my main view i have 3 buttons, each button will load a different nib. and each new nib is having one back button to come back to main view.
when i click one the back button of any view to move to the main view the dealloc of that view is not getting called? i didnt understood this.
can anyone explain when those views dealloc will be called?
if the dealloc method hasn't been called, it means that your retained your viewController object by hands. for example, in this case dealloc will not be called after clicking back button to return
MyViewController *controller = [[MyViewController alloc] init];
[self.navigationController pushViewController:controller animated:YES];
You should add
[controller release];
to this code to be sure that your instance of viewController will be deallocated. If you are absolutely sure, that you had sent equal number of alloc(or any message that increases object's retainCount) and release messages for your object and dealloc method doesn't be called anyway, it will be more complex. I hope that this answer will help. If you will find that your situation is "more complex", post a comment, then I'll try to explain with more details.
I too would like to dive deeper into understanding memory management details (below surface level) where it comes to controllers being pushed on and off of the stack. I built my framework from the text, "Beginning iPhone 3 Development" by Mark and LaMarche, but that text effectively re-uses sub-controllers and their dealloc methods never get called.
I have noticed that repeated use of a sub-controller with a NIB containing a UIWebView that calls Google's web directions url ... eventually results in a memory warning and my data is lost. This involves repeated "reuse" of the sub-controller.
If you can point me as well to in depth text that goes into nav controller and sub view memory management, that would be excellent.

iPhone SDK: Navigation among view controllers causes crash

(Sorry, I restarted this thread as I incorrectly accepted the answer for my problem.)
My app is crashing when I navigate two view controllers in my application. For example, if I do this sequence:
RootController ViewControllerA
ViewControllerB ViewControllerA
My app crashes.
It crashes when I pressed the back button in ViewControllerB. So, It seems like it is with two or more ViewControllers being pushed. Each by themselves work.
I don't know why.
I don't see any output to the console. Is there some type of debugging I should put?
I looked at the dealloc() to make sure all properties were being release before dealloc()
Any ideas?
Thank you.
Is your 2nd view controller holding a reference to the 1st without retaining it? If so, when your 2nd is dealloc'd it could release the 1st and cause it to have no references and be an invalid object.