views:

95

answers:

2

Hey I have been battling with this problem for a while now. Perhaps there is something I am missing in knowledge about multi threading but here is what happens. When I create an nsoperation queue any variables that are allocated become cleared after the "[request startSynchronous];" line of code. Here is what I'm talking about:

@implementation imageLoadOperation
@synthesize object;

-(id)initWithObject:(NSMutableArray *)receivedObject
{
 ...
 object = receivedObject;
 ...
}
- (void)main {
 ...
//send request
 printf("retreiving photo info from server\n");

 NSURL *url = [NSURL URLWithString:[siteUrl stringByAppendingString:@"/connect.php"]];
 ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
 [request setPostValue:@"lookAtPhoto" forKey:@"purpose"];
 [request setRequestCookies: [ASIHTTPRequest sessionCookies]];

The object still exists here

[request startSynchronous];

Then the object disappears here!

I'm sure this has something to do with a gap in principle understanding but I have been rearranging the code for days now to no success.

...

+1  A: 

awww gosh I can't believe it. I wasn't setting the object in the correct way to trigger the property retain. > self.object

Dobler
What? I don't understand this solution, though I think it could be useful to me. Could you elaborate?
IQpierce
Okay this is strange, I was getting a similar problem and it also went away when I did the equivalent of:[object retain];in initWithObject. But I don't understand why this is necessary, or makes any difference, when I already had (nonatomic, retain) on the variable's property definition. Shouldn't it already be retained on my class? If so, why am I having to retain it a second time?
IQpierce
A: 

IQpierce, in answer to your question, the code above doesn't call the synthesized accessor, which is what would perform the retain for you.

This:

object = receivedObject;

should be:

self.object = receivedObject;

or perhaps to be clearer (although it's obviously the same thing):

[self setObject:receivedObject];

Hope that helps!

paulbailey