I’ve declared two NSMutableArrays in the interface of one of my view controllers, as you can see in the code below. However, after synthesizing the properties, I attempt to initialize my class’ ivars in viewDidLoad. If I step over this process in debugger, I see that it is offsetting memory allocation by one ivar, if that makes any sense. So, for example, as I am initializing the first NSMutableArray, I can watch the memory address get assigned to the other NSMutableArray ivar. The NSMutableArray that the code should be initializing remains a null memory address. This odd “offset” in memory allocations is try for initializing the second NSMutableArray too…it is initialized in my DataHelper ivar’s memory location. This is causing errors to be thrown later in the code like:
-[DataHelper count]: unrecognized selector sent to instance
Where it is expecting a reference to an NSMutableArray in memory, it is instead pointing to the DataHelper memory address. Has anyone ever experienced anything like this? I’m using ARC, the latest version of Xcode, and iOS 5.1.
MyViewController.h
#import <UIKit/UIKit.h>
#import "DataHelper.h"
@interface MyViewController : UIViewController
{
DataHelper *dataHelper;
NSMutableArray *recentPosts;
NSMutableArray *popularPosts;
}
@property (nonatomic, strong) DataHelper *dataHelper;
@property (nonatomic, strong) NSMutableArray *recentPosts;
@property (nonatomic, strong) NSMutableArray *popularPosts;
@end
viewDidLoad in MyViewController.m
@implementation MyViewController
@synthesize dataHelper, recentPosts, popularPosts;
- (void)viewDidLoad
{
[super viewDidLoad];
recentPosts = [[NSMutableArray alloc] init];
popularPosts = [[NSMutableArray alloc] init];
dataHelper = [[DataHelper alloc] init];
// I've also tried initializing the ivars as above, with "self." prefix
recentPosts = [dataHelper getSuggestionsByMostRecent:1];
popularPosts = [dataHelper getSuggestionsByPopular:1];
}
There are memory readout issues with LLDB in XCode (4.3.1 seems to be affected too) so i suggest you use GDB for debugging.