0

I have a problem where a variable is randomly deallocated or corrupted and I get an NSInvalidArgumentException. It doesn't always happen but I'm able to reproduce the problem after a few tries.

I've tried a few ways to check if the property is the right type but with no success.

Here is the variable when everything is working Here is the variable when everything is working

Here is the variable when the app crashes Here is the variable when the app crashes

I've noticed that the "isa = (Class)" part now returns an error instead of "CLLocation" so I'm trying to check it but it's protected.

[fromPoint->isa isKindOfClass:[CLLocation class]]

I've tried the answers here but I'm still getting the exception.

Objective c isKindOfClass missunderstanding?

isa pointer in objective-c

Thanks!

Community
  • 1
  • 1
Svavar
  • 205
  • 1
  • 5

1 Answers1

6

Looks you have references to deallocated objects. Try to run the debugger with NSZombieEnabled=YES. Set this by opening Product>Edit Scheme... and adding a row to the "Environment Variables" of the Run configuration.

Krumelur
  • 31,081
  • 7
  • 77
  • 119
  • 2
    Also turn on some options under **Diagostics > Memory Management** in your debugging Scheme to track down potential memory issues. – Jay Oct 10 '12 at 17:06
  • What Krumelur said; the crash is a symptom and your attempt to validate the isa is an attempt to address the symptom. Doing so won't fix the actual bug. – bbum Oct 10 '12 at 17:46
  • Thanks for the quick replies. I think the bug is that `fromPoint` was being set to a pointer reference: `fromPoint = locationController.currentLocation;` I've changed it to this: `fromPoint = [[CLLocation alloc] initWithLatitude:locationController.currentLocation.coordinate.latitude longitude:locationController.currentLocation.coordinate.longitude];` I'm thinking that `locationController.currentLocation` was getting deallocated causing the bug. – Svavar Oct 11 '12 at 11:15