Is passing NSManagedObjects between ViewControllers a bad idea? I have an iPad app and I seem to run into random bad access crashes and sigbart errors.
These NSManageObjects are coming from CoreData and I wonder if they sometimes just drop out of memory and cause this. I was hoping to just pass them from controller to controller to avoid doing a fetch on every viewcontroller.
Sounds like it's a matter of bad object memory allocation practices. As long as you're not multithreading your app and there is only one managedObjectContext (typical), you can pass these NSManagedObjects between VeiwControllers no problem.
What's probably happening is you're passing the reference from one ViewController to another without incrementing it's refcount with a retain message. This can get dicey.
What I'd recommend is having a retain property on your ViewControllers, like
@property (nonatomic, retain) NSManagedObject *yourObject;
Then, when you get your managed object, keep it like this:
self.yourObject = ...;
... and when you want to pass it to another view controller:
otherViewController.yourObject = ...;
And it will take care of setting retain/release for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With