Today I got a “EXC_BAD_ACCESS” ,so I debug the code to solve the problem. Now I find out where
the problem is, but I don’t know why. Can you help me ?
in the
-(void) dealloc
{
….
[self.scrollView release];
// if I add comment to this line above ,my app will work, else it will die.
……
}
these are the places where I used the [scrollView]
@interface ChatFriendInfoController :UIViewController
{
UIScrollView *scrollView;
}
@property (nonatomic, retain) IBOutlet UIScrollView *scrollView;
@implementation ChatFriendInfoController
@synthesize scrollView;
self.scrollView.frame = CGRectMake(0, 64, 320, 416);
self.scrollView.alwaysBounceVertical = YES;
self.scrollView.contentSize = CGSizeMake(320, 960);
[self.scrollView addSubview:infoTable];
That’s All . Thank you.
When the @property line for scrollView is defined with “retain”, then the accessor functions that XCode builds for you will already have retain and release calls built-in.
So, any time you use self.scrollview = , you are actually calling [self setScrollView:] which will release any previous object and retain the new one. So you can release the object and set the variable to nil with just self.scrollview = nil;
With the code above, I can’t tell if you allocating and initializing a new UIScrollView object. If you haven’t, then there is nothing to release and trying to do so will crash.