简体   繁体   中英

Memory management issue: Object used after release

This code is returning an error:
458:3 Reference-counted object is used after it is released

 - (id)createObjectFromURL: (NSURL*)URL
                    query: (NSDictionary*)query {
  id target = nil;

    if (self.instantiatesClass) 
  {
    target = [_targetClass alloc];
  } 

  else 
  {
    target = [_targetObject retain];
  }

  id returnValue = nil;
  if (_selector) 
  {
    returnValue = [self invoke:target withURL:URL query:query];
  } 
  else if (self.instantiatesClass) 
  {
    returnValue = [target init];
  }

  [target autorelease];
  return returnValue;
}

What about if you try to do this:

else if (self.instantiatesClass) 
{
  returnValue = [[target init] autorelease];
}
return returnValue;

Because you're not init ing the target if you don't go to else if.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM