0
votes

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?

2
Sounds to me like something else released your "MyOperationClass" myArray object. If it were my code, I'd run Xcode's Instruments and use the ObjectAlloc template to see who is retaining and releasing the elements of your object. - Michael Dautermann
oh... heh. I also see the ARC keywords "strong" in your interface declaration. I don't have a lot of experience with ARC yet, personally, but I thought the big "win" of ARC was that you didn't have to mess with managing dealloc or releases. - Michael Dautermann
i don't have ARC in my project, so i have to change it in nonatomic retain?...in fact i want do another question on stack overflow about this... - Piero
if you are using ARC, you don't have to release your member variables. Are you using ARC? Also, try turning on zombies and see if that points out the problem. - nielsbot

2 Answers

1
votes

you might not have allocated memory to object that you are releasing

1
votes

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];