I created some something in my operation queue(_opQueue), and i want to release them in this queue too. Here is my code, _opQueue was created form "dispatch_queue_create("Data_Serial_Operation_Queue", DISPATCH_QUEUE_SERIAL);"
@implementation CrowdPot
- (void) dealloc {
[_queryString release],_queryString = nil;
[_sortedItems release],_sortedItems = nil;
objc_setAssociatedObject(_indexesDictionary, ctIndexDictionaryTypeKey, nil, OBJC_ASSOCIATION_ASSIGN);
[_indexesDictionary release],_indexesDictionary = nil;
[super dealloc];
}
- (id)init
{
self = [super init];
if (self)
{
dispatch_sync(_opQueue, ^{
_sortedItems = [[NSMutableArray alloc] initWithCapacity:128];
_indexesDictionary = [[NSMutableDictionary alloc] initWithCapacity:28];
_initialRange = NSMakeRange(NSNotFound, 0);
_needRefill = YES;
});
}
return self;
}
- (oneway void)release
{
dispatch_async(_opQueue, ^{
[super release];//revise
});
}
In the release method I use "[super release]" in a block, which I think might retain self(using the keyword 'super' retain self's retain count). I think it's not a elegance implementation and even wrong.
Then how to write the release method if i want to release these data in my _opQueue? Is another way to do this in this case, anyone help?
Here is a way to release data in a specific thread which i got it from internet.
-(oneway void)release{
//ensure dealloc occurs on our _addressBook thread
//we do this to guarantee that we are removed from the weak cache before someone else ends up with us.
if (_addressBookThread && ![[NSThread currentThread] isEqual:_addressBookThread]) {
[self performSelector:_cmd onThread:_addressBookThread withObject:nil waitUntilDone:NO];
} else {
[super release];
}
}