0

I am getting this error in iOS8 only, working fine in iOS9

[DetailView respondsToSelector:]: message sent to deallocated instance 0x7c818a20

Is there any way by I can find where my object is de-allocating?

I know there is tool zoombie in xcode, but it is only providing the above info, I have also tried profiling but nothing help.

I have also placed exeption breakpoint but control is not breaking anywhere in code.

See attached imageenter image description here

In My MainVC.m set a property @property (nonatomic,strong) DetailView *d;

On click of a button in MainVC.m (I have to add this detailview as a subview)

_d = [[DetailView alloc]initWithData:dict andImgId:[[_arrayHotelimg objectAtIndex:0] valueForKey:@"img_id"] isTour:NO];
_d.dictData = [_dbObj getHotelDescriptionDataFromHid:_iTabId];
_d.delegate = self;
[self.view addSubview:_d];

DetailView.m

-(id)initWithData:(NSDictionary*)dict andImgId:(NSString*)imgId isTour:(BOOL)isTour{
    self = [super initWithFrame:CGRectMake(0, TOP, SCREEN_WIDTH, SCREEN_HEIGHT)];
    if (self)
    {
    self.arrGalleryImages = [NSMutableArray new];
    _dbObj = [Database Connetion];

    NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:@"DetailView" owner:self options:nil];
    self = [subviewArray objectAtIndex:0];
    self.frame = CGRectMake(0, TOP, SCREEN_WIDTH, SCREEN_HEIGHT);
    }
    return self;
}

Can anyone help me on how can I find which code is breaking or where is object deallocating?

Why is it working on iOS9 and not on iOS8 ?

Mayank Jain
  • 5,663
  • 7
  • 32
  • 65
  • Did you add "AllExeption break point"? – MCMatan Aug 24 '16 at 10:36
  • yes but code is control is not breaking anywhere. See my updated post – Mayank Jain Aug 24 '16 at 10:37
  • I help you now.I had same problem when navigating to next view controller or in some places it shows error like that.Show your naviagtion coding first. – user3182143 Aug 24 '16 at 10:42
  • [http://stackoverflow.com/questions/11170614/viewcontroller-respondstoselector-message-sent-to-deallocated-instance-crash/11171042#11171042](http://stackoverflow.com/questions/11170614/viewcontroller-respondstoselector-message-sent-to-deallocated-instance-crash/11171042#11171042) – Ketan Parmar Aug 24 '16 at 11:01

3 Answers3

1

Add method -dealloc() in your class implementation and put breakpoint inside. Then you will know when exactly your object is deallocated.

Pavel Gatilov
  • 2,570
  • 2
  • 18
  • 31
  • yes control is going in dealloc.. but how can I find more info – Mayank Jain Aug 24 '16 at 10:43
  • No, `-dealloc()` will got called every time for any viewcontroller when your VC will dealloc. This is different thing! – Ketan Parmar Aug 24 '16 at 10:45
  • @KetanParmar -dealloc() is not VC method, it is method on NSObject. And how it is different thing? According to apple docs, dealloc called on object to deallocate allocated memory. – Pavel Gatilov Aug 24 '16 at 10:49
  • 1
    Yeah but OP getting `message sent to deallocated instance`. So OP is asking for finding object which is got deallocing and this method(`-dealloc()`) will got called when whole class is dealloc !!!! – Ketan Parmar Aug 24 '16 at 10:52
  • @MayankModi so now, you got exact moment when your object of class DetailView is deallocated. And now you need to look at your code and figure out why it was deallocated. Maybe you holding weak reference, maybe you poped your ViewController which was holding reference to this view. – Pavel Gatilov Aug 24 '16 at 10:57
  • @PavelGatilov its strong reference and I am adding a subview not pushing VC – Mayank Jain Aug 24 '16 at 11:03
  • @MayankModi Can you show a piece of code, where you creating an instance of view and what do you do before receiving error message. – Pavel Gatilov Aug 24 '16 at 11:05
  • @MayankModi : add relevant code in question. So that anyone can get idea and you may got solution! – Ketan Parmar Aug 24 '16 at 11:05
0

Analyze your code by pressing mac+shift+B. It will show the leak object and retain/release count of objects.

Bhadresh Mulsaniya
  • 2,610
  • 1
  • 12
  • 25
0

I think delegate property may be weak reference. Once try to make it strong. and make d also strong if it is weak. And check if it solve the issue!

Update :

what happen if any one click more than one time on button ? It will redefine _d i think. so old one (_d) which was already added to self.view will not getting point or will loose reference. So, if you want to add multiple view on button click then don't declare it as property or globally. declare and alloc it in that action method it self like,

 DetailView *d = [[DetailView alloc]initWithData:dict andImgId:[[_arrayHotelimg objectAtIndex:0] valueForKey:@"img_id"] isTour:NO];
Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75
  • property (nonatomic, assign) id delegate; and property (nonatomic,strong) DetailView *d; – Mayank Jain Aug 24 '16 at 11:10
  • where you doing `_d = [[DetailView alloc]initWithData:dict andImgId:[[_arrayHotelimg objectAtIndex:0] valueForKey:@"img_id"] isTour:NO];` ? In viewDidload? – Ketan Parmar Aug 24 '16 at 11:29
  • On click of a button in MainVC.m (I have to add this detailview as a subview) – Mayank Jain Aug 24 '16 at 11:31
  • then try `self = [subviewArray objectAtIndex:0];self.frame = CGRectMake(0, TOP, SCREEN_WIDTH, SCREEN_HEIGHT);` directly in action method instead of `init` method of your subclass of your `UIView`. write all necessary code within action method. – Ketan Parmar Aug 24 '16 at 11:53
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/121736/discussion-between-mayank-modi-and-ketan-parmar). – Mayank Jain Aug 24 '16 at 12:35