• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
RE: container retain/release problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: container retain/release problem


  • Subject: RE: container retain/release problem
  • From: "Jonathan E. Jackel" <email@hidden>
  • Date: Thu, 10 Feb 2005 15:50:57 -0500
  • Importance: Normal

Are you sure that updates is being retained?  Have you stepped through the
debugger to verify that?

I seem to recall a discussion a couple of weeks ago that isKindOfClass:
basically does not work with mutable subclasses of class clusters.  In your
code, you retain updates only if [updates isKindOfClass:[NSMutableArray
class]] is true.  If I remember the discussion correctly, it will always
return false.  Use the debugger to see if it is really working.

Also, you can message nil, and if an object does not exist, it is equal to
nil, so you can simplify your code a bit:

>      if (dict)
>      {
>          [updates release];//Doesn't matter if updates exists.
>          updates = [[dict objectForKey:@"Updates"] retain];
>          if ([updates isNotAMutableArray]) //I'm making this up.
>	     [updates release];
>              updates = nil;
>
>          if (delegate)
>              [delegate dataSourceReloaded:self];
>      }

Jonathan

> -----Original Message-----
> From: cocoa-dev-bounces+jonathan=email@hidden
> [mailto:cocoa-dev-bounces+jonathan=email@hidden]On Behalf
> Of Paul Forgey
> Sent: Thursday, February 10, 2005 2:25 AM
> To: email@hidden
> Subject: container retain/release problem
>
>
> I've got an NSDictionary which I've built as per the quoted code below.
>   dict will autorelease, however I've got an NSArray element in there
> which I've retained.  So therefore, it should stick around, shouldn't
> it?  Problem is after the autorelease pool gets run, my instance
> variable 'updates' has either been released or completely trashed.
> Copying the array doesn't make things act any differently.  What
> exactly am I doing wrong?
>
> -(void)connectionDidFinishLoading:(NSURLConnection *)conn
> {
>      NSMutableDictionary *dict;
>      NSString *errorString;
>      NSPropertyListFormat format;
>
>      dict = [NSPropertyListSerialization propertyListFromData:recvBuffer
>          mutabilityOption:NSPropertyListMutableContainersAndLeaves
> format:&format
>          errorDescription:&errorString];
>
>      [connection release];
>      connection = nil;
>
>      [recvBuffer release];
>      recvBuffer = nil;
>
>      if (dict != nil)
>      {
>          if (updates != nil)
>              [updates release];
>          updates = [dict objectForKey:@"Updates"];
>          if (updates != nil && ![updates isKindOfClass:[NSMutableArray
> class]])
>              updates = nil;
>          else
>              [updates retain];
>
>          if (delegate != nil)
>              [delegate dataSourceReloaded:self];
>      }
>      else
>      if (delegate != nil)
>      {
>          [delegate dataSource:self didFail:errorString];
>      }
> }
>
>  _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: container retain/release problem
      • From: Paul Forgey <email@hidden>
References: 
 >container retain/release problem (From: Paul Forgey <email@hidden>)

  • Prev by Date: Re: Philosophy of FSRef - way
  • Next by Date: Re: Welcome to the "Cocoa-dev" mailing list
  • Previous by thread: container retain/release problem
  • Next by thread: Re: container retain/release problem
  • Index(es):
    • Date
    • Thread