1

I have got the following error, -[CALayer isKindOfClass:]: message sent to deallocated instance, although I am using ARC

What happen is,

  • View Controller A has a table view and search field.
  • View Controller B has a subView of type UIView, where this subview contains UITextView.

When I navigate to View Controller B and navigate back to View Controller A, if I tab on the search field the App will crash and gives me the above error.

I have done lots of debugging and I found the deallocated instance is the UITextView in the View Controller B.

If you could you please help me, why this happen.

Many thanks.

Ofcourse
  • 617
  • 1
  • 7
  • 19
  • 1
    post your code for both controllers – meronix Mar 11 '15 at 09:42
  • From what i understood. Your navigation flow is ViewA->ViewB, as you come back to ViewA<-ViewB, the instance of UITextView and all other objects in ViewB will normally get deallocated. The possibility of crash on clicking any UIControl in ViewA, due to deallocation of any objects in viewB is not correct scenario, which does't have much probability when you use navigation controller. – Dileep Mar 11 '15 at 10:01
  • in ViewA, viewWillAppear, write `yourTF.text = @"";` – Fahim Parkar Mar 11 '15 at 10:01

1 Answers1

0

Without code it's hard to guess what you are doing wrong. You might be accessing the UITextView from ViewController A, for instance.

In any case, you might consider using NSZombie to track the error down. You can enable it in the Xcode Edit Scheme menu under "Diagnostics > Memory Management". See this StackOverflow post for a description how to profile NSZombies.

Community
  • 1
  • 1
Dennis
  • 2,119
  • 20
  • 29
  • Thanks you @Dennis of course I have tried Zombie, but it didn't work for me, when I run Zombie, when I reach VC B for some reason I can't navigate back to VC A. I know without code it hard, but VC B associated with many subviews classes, which make it harder – Ofcourse Mar 11 '15 at 11:38
  • @DILi , Thank you. what you said it does make sense, but I could't figure out the issue. what exactly happen is; when VC B load it instantiate few UIViews these views are independent class and each one has XIB, then I add the instantiated views to an array, so the user then can navigate back and forth, the UITextView is in one of these views – Ofcourse Mar 11 '15 at 11:39
  • The problem is that the `UITextView` is going to be deallocated by iOS when you navigate away from the view. I would propose that you store the text of the `UITextView` in an array, rather than the view itself. – Dennis Mar 11 '15 at 11:47