Hey Guys,
I'm rather new to Objective C programming, but I do have several years of programming experience in various other languages.
A few days ago I began working on an app (I'm using the storyboard if that matters) and when trying to "release" an object for memory cleanup, Xcode gave me an error saying I can't release an object with ARC. At that point I didn't know what ARC was, so I looked it up and read up on it and discovered it handles memory management for me. It sounded nice, so I decided to stick with it.
Well, earlier today I was testing the app and noticed that when changing between view controllers, the memory from the previous controller is never released. I set break points on the "dealloc" methods and they aren't being triggered. I also used the static analyzer as well as the leak detector to see if I could track down the issue, however neither tool had any results.
Now, I'm sure this has something to do with me horribly misunderstanding either ARC or some aspect of Objective C.
On most properties (such as IBOutlets for UI elements) I use "weak" and I'm using "strong" only when necessary (like when an object needs to be allocated). Also, inside of any blocks I use a "weakSelf" ( __unsafe_unretained MyEventsController *weakSelf = self; )rather than "self".
My project is a bit big, so I'd rather not post the entire thing. However, here are some snippets.
One of my view controller's headers:
Sometimes I use a navigationController to push to the next view controller. Here's the code I use from that, do I have to release(or "pop") the current controller if I'm using a navigationController?
Hopefully someone can help me find the issue.
Thanks,
Sean
I'm rather new to Objective C programming, but I do have several years of programming experience in various other languages.
A few days ago I began working on an app (I'm using the storyboard if that matters) and when trying to "release" an object for memory cleanup, Xcode gave me an error saying I can't release an object with ARC. At that point I didn't know what ARC was, so I looked it up and read up on it and discovered it handles memory management for me. It sounded nice, so I decided to stick with it.
Well, earlier today I was testing the app and noticed that when changing between view controllers, the memory from the previous controller is never released. I set break points on the "dealloc" methods and they aren't being triggered. I also used the static analyzer as well as the leak detector to see if I could track down the issue, however neither tool had any results.
Now, I'm sure this has something to do with me horribly misunderstanding either ARC or some aspect of Objective C.
On most properties (such as IBOutlets for UI elements) I use "weak" and I'm using "strong" only when necessary (like when an object needs to be allocated). Also, inside of any blocks I use a "weakSelf" ( __unsafe_unretained MyEventsController *weakSelf = self; )rather than "self".
My project is a bit big, so I'd rather not post the entire thing. However, here are some snippets.
One of my view controller's headers:
Code:
#import <UIKit/UIKit.h>
@interface MyEventsController : UIViewController <UITableViewDelegate, UITableViewDataSource,UINavigationControllerDelegate>
{
}
@property (nonatomic,weak) IBOutlet UITableView *myEventView;
@property (nonatomic,strong) NSArray *myEventsArray;
@property (nonatomic,strong) NSMutableArray *currentEvents;
@property (nonatomic,strong) NSMutableArray *upcomingEvents;
@property (nonatomic,strong) NSMutableArray *pastEvents;
@property (nonatomic,strong) NSDateFormatter *dateFormat;
@end
Sometimes I use a navigationController to push to the next view controller. Here's the code I use from that, do I have to release(or "pop") the current controller if I'm using a navigationController?
Code:
EventController * controller = (EventController *)[self.storyboard instantiateViewControllerWithIdentifier:@"EventPage"];
[self.navigationController pushViewController:controller animated:YES];
Hopefully someone can help me find the issue.
Thanks,
Sean