Shinonuma
Shinonuma

Reputation: 491

Error: Message sent to deallocated instance

I've made a popup view, with a UIButton on it which closes the view. Whenever I put on the button, the program quits with this message: [MTPopupWindow performSelector:withObject:withObject:]: message sent to deallocated instance 0x84675f0 Here is the header file and source file to use the class I use this line of code:

[MTPopupWindow showWindowWithContent:@"Some text here" insideView:self.view];

I thought that there was something wrong with deallocating my objects too soon but since I'm using ARC I'm not sure what is causing this problem. I think the problem is in this line of code:

[self.closeBtn addTarget:self action:@selector(closePopupWindow) forControlEvents:UIControlEventTouchUpInside];

But I don't see anything wrong with this.

Upvotes: 0

Views: 211

Answers (1)

Jim Puls
Jim Puls

Reputation: 81132

You should have known there was a problem when you wrote this:

// Cast to void because we don't use the result (otherwise compiler warning)

Since you don't use the result, ARC believes that it's free to insert a release on your object after that line, which means the object is getting deallocated way early.

There are a number of ways around this; take a look at things like NS_RETURNS_RETAINED or having the caller of your popup window hold a strong reference to it.

Upvotes: 1

Related Questions