• 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: Paul Forgey <email@hidden>
  • Date: Thu, 10 Feb 2005 14:25:35 -0800

Yes, [updates isKindOfClass:[NSMutableArray class]] is returning true, and updates is being retained. I have verified that with the debugger.

Even if we weren't, updates would then set to nil.

If I modify my code so that 'dict' is retained, things work. Of course I then have a memory leak because it will never be released in that case.

On Feb 10, 2005, at 12:50 PM, Jonathan E. Jackel wrote:

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:
email@hidden


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: email@hidden
References: 
 >RE: container retain/release problem (From: "Jonathan E. Jackel" <email@hidden>)

  • Prev by Date: Re: NSKeyedUnarchiver - unarchiving on a background thread
  • Next by Date: NSDocumentController redisplay NSPanel
  • Previous by thread: RE: container retain/release problem
  • Next by thread: Re: container retain/release problem
  • Index(es):
    • Date
    • Thread