Skip to content

[v0.31.0] crash in RCTImageLoader.m #9497

@ymmuse

Description

@ymmuse

I got are crash reports from app.

qq20160821-0 2x

code at : RCTImageLoader.m

  // Download image
  __weak __typeof(self) weakSelf = self;
  RCTNetworkTask *task = [networking networkTaskWithRequest:request completionBlock:^(NSURLResponse *response, NSData *data, NSError *error) {
    if (error || !response || !data) {
      NSError *someError = nil;
      if (error) {
        someError = error;
      } else if (!response) {
        someError = RCTErrorWithMessage(@"Response metadata error");
      } else {
        someError = RCTErrorWithMessage(@"Unknown image download error");
      }
      completionHandler(someError, nil);
      [weakSelf dequeueTasks];
      return;
    }

   dispatch_async(self->_URLCacheQueue, ^{   //  **** Line 462 at here **** //
      __typeof(self) strongSelf = self;
      if (!strongSelf) {
        return;
    }

I see completionBlock method using the weakSelf itself, but I don't understand the block that doing cache the response nested in completionBlock why use this logic:

   __typeof(self) strongSelf = self;
   if (!strongSelf) {
     return;
   }

the 'self' object in cache response block will be retain when the block occurs copy, it may be released ? why not using weakSelf instead of self write it like this:

   __typeof(self) strongSelf = weakSelf;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions