Reputation: 9273
i have a NSOperationQueue with NSOperation, in my NSOperation .h i have this property:
@interface MyOperationClass : NSOperation
@property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController;
@property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (strong, nonatomic) NSManagedObject *myObject;
@property (nonatomic, retain) NSMutableArray *myArray;
@end
and this in the dealloc of the NSOperation in the .m file:
- (void)dealloc {
[__fetchedResultsController release];
[__managedObjectContext release];
[myObject release];
[myArray release];
[super dealloc];
}
in another class i add the operation in the queue in this way:
MyOperationClass *myOperation = [[MyOperationClass alloc] init];
[myOperationQueue addOperation:myOperation];
[myOperation release];
but give me a bad_exc_access on the line of [myArray release]; what i wrong?
EDIT: i notice that in the code i do this:
wikiEpisodeArray = [NSMutableArray arrayWithArray:otherArray];
maybe is this? i don't have initialized it with [NSMutableArray alloc] ?
EDIT 2: i have another similar problem, i have also this variable:
@property (nonatimc, retain) NSString *previousTime;
and i initialized it in this way:
previousTime = [[NSString alloc] init];
and in the code i never release it, only in the dealloc, and now i receive a bad exc access on this line:
[previousTime release];
in the dealloc... why?
Upvotes: 0
Views: 810
Reputation: 5308
If you don't have arc, then you have to use (nonatomic, retain) (or assign if not retaining it).
Also, any object that you don't explicitly alloc, should be returned autoreleased. so don't release them.
If you want to create a mutable array that you own with another one you should do
[NSMutableArray alloc] initWithArray:aArray];
for the NSString, use (nonatomic, copy), also, again, when you assign a nsstring with @"something" you are assigning an autoreleased one overriding the previous [NSString alloc] init].
So, if you want to own the string you should do:
[NSString alloc] initWithString:aString];
Upvotes: 1
Reputation: 6166
you might not have allocated memory to object that you are releasing
Upvotes: 1