0

In short, I need to know if I am able to log the storage type for a variable.

Specifically, I want to log whether a variable has the __block storage type modifier applied to it.

Ideally, I'm looking for something like:

NSLog(@"storage type: %@", [localVar storageType]);

In case you're wondering, I think I just figured out a memory leak I've been debugging for the past few days, and I want to test if my assumption is correct.

I'm using ASIHttpRequest with setCompletionBlock and setFailedBlock, but I'm passing my request object to a convenience method that does the actual setup of the blocks, like so:

- (void)getAllHighlights:success:(ASIBasicBlockWrapper)cb1 fail:(ASIBasicBlockWrapperFail)cb2{

    // blah blah blah

    __block ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
    [request setRequestMethod:@"GET"];
    [request setDelegate:self];

    [self executeAsynchronousRequest:request onSuccess:cb1 onFail:cb2];
}

Then, executeAsynchronousRequest sets up the Blocks and starts the request:

- (void) executeAsynchronousRequest:(ASIFormDataRequest *)request onSuccess:(ASIBasicBlockWrapper)cb1 onFail:(ASIBasicBlockWrapperFail)cb2
{
    [request setCompletionBlock:^{
        int statusCode = [safeRequest responseStatusCode];
        NSString *statusMessage = [self statusErrorMessage:statusCode];
        cb1([safeRequest responseString],statusMessage);
    }];
    [request setFailedBlock:^{
        cb2(safeRequest);
    }];

    [request startAsynchronous];    
}

My hunch tells me that even though I set up my request object as __block ASIFormDataRequest *request, when it's used within executeAsynchronousRequest, it's lost the __block storage type since it has only been typed as (ASIFormDataRequest *)request.

Thanks!

djibouti33
  • 12,102
  • 9
  • 83
  • 116

1 Answers1

0

you aren't modifying request in a block, so __block isn't going to do anything for you... if you were passing in request to a block, it wouldn't be copied, it would keep the locally scoped version when you passed it into the block.

Grady Player
  • 14,399
  • 2
  • 48
  • 76
  • hmmm...if i "recast" my request object inside executeAsyncRequest like so: __block ASIFormDataRequest *blockSafeRequest = request; and then use blockSafeRequest within my block, all my memory leaks pertaining to ASIHTTPRequest go away. – djibouti33 Apr 23 '12 at 23:03
  • setCompletionBlock and setFailedBlock do an explicit copy of the block. could this have any impact as to why casting the request argument with __block is successful at eliminating the leaks? – djibouti33 Apr 23 '12 at 23:08
  • if you are just trying to track down leaks, have you used the static analyzer yet? – Grady Player Apr 24 '12 at 22:09