Re: NSLog preventing a crash?
Re: NSLog preventing a crash?
- Subject: Re: NSLog preventing a crash?
- From: Andrew Merenbach <email@hidden>
- Date: Tue, 24 Jul 2007 07:27:55 -0700
You seem to be over-retaining, so I'm sure that your crash is caused
by something else. Your code should look something like this:
while (theDict = [theRes fetchRowAsDictionary]) {
RCBlah *blah = [[RCBlah alloc] init]; // use of -new is discouraged
these days
[blah setAsDict:theDict]; // your -setAsDict: method should retain
or copy theDict
[allBlahs addData:blah]; // if you're storing theDict as an
individual item in allBlahs, you should have a -retain or -copy
*inside* the -addData: method
[blah release]; // you were missing this in your initial code; if
you don't include it you'll have a memory leak
}
With regard to -setAsDict:
- (NSDictionary *)myDictionary {
return [[myDict retain] autorelease];
}
- (void)setMyDictionary:(NSDictionary *)aDictionary {
if (aDictionary != myDict) {
[myDict release];
myDict = [aDictionary retain];
}
}
If -addData: does something similar--adding "blah" to an
NSDictionary, NSArray, or NSSet--then you'll not need to retain or
copy the items manually, since a retain will be done for you.
Without knowing more of your code we can't offer much more
assistance, I think--we don't know how your -setAsDict: method
currently functions, nor do we know how -addData: functions.
Also, once you've fixed these methods, one way to help debug your
crash is to set NSZombieEnabled to YES in your build settings (see
<http://developer.apple.com/technotes/tn2004/tn2124.html> for some
good debugger tips, including NSZombieEnabled information). This
will help figure out if an object is being deallocated before you can
use it--and help to figure out which object.
Cheers,
Andrew
On Jul 24, 2007, at 6:50 AM, Rob Chahin wrote:
Here's the code I'm using. I'm not creating each dictionary, I'm
actually using a pointer to a dictionary:
while(theDict = [theRes fetchRowAsDictionary])
{
RCBlah *blah = [RCBlah new];
[blah setAsDict:[theDict copy]];
[allBlahs addData:blah];
}
(I rarely do desktop programming, so I'm likely to use the terms
'dictionary' and 'pointer to dictionary' interchangeably.. it leads
to a lot of errors)
- R
I am curious on why you think you must copy a dictionary before
you place it in an array? No such requirement exists.
-Shawn
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden