Re: Cocoa Newbie Thread/Memory Problems
Re: Cocoa Newbie Thread/Memory Problems
- Subject: Re: Cocoa Newbie Thread/Memory Problems
- From: Quincey Morris <email@hidden>
- Date: Tue, 16 Mar 2010 10:57:46 -0700
On Mar 16, 2010, at 09:57, Dave wrote:
> At present I am not doing anything with the result, except assigning the values so I can look at them in the debugger. The problem is that when I look at the items in the array passed to the view controller the data retrieved is not as it should be (contains "invalid" or "out of scope" in the debugger). Sometimes the values are correct, but most of the time they are garbage.
>
> The method called:
>
> - (void)parser:(ParserBase*)theParser didParseItems:(NSArray*)theItemDictionaryArray
> {
> NSEnumerator* myArraytEnumerator = [theItemDictionaryArray objectEnumerator];
> NSDictionary* myDictionary;
> NSString* myObjectNameString;
> NSString* myFactYearString;
> NSString* mtFactMonthString;
> NSString* myFactDayString;
> NSString* myFactSourceDatabaseString;
> NSString* myFactTextString;
> static int myObjectCount=0;
>
> while (myDictionary = [myArraytEnumerator nextObject])
> {
> myObjectNameString = [myDictionary objectForKey:[ParserXML parserObjectFieldName]];
> myFactYearString = [myDictionary objectForKey:kField_FactYear];
> mtFactMonthString = [myDictionary objectForKey:kField_FactMonth];
> myFactDayString = [myDictionary objectForKey:kField_FactDay];
> myFactSourceDatabaseString = [myDictionary objectForKey:kField_FactSourceDatabase];
> myFactTextString = [myDictionary objectForKey:kField_FactText];
> myObjectCount++;
> }
> }
> myObjectNameString, myFactYearString, mtFactMonthString, myFactDayString, myFactSourceDatabaseString, myFactTextString are gargage most of the time.
You may just be falling afoul of code optimization. Almost all of your variables are unreferenced after being set, and the compiler is very good at shortening their "effective" lifetime (in terms of source code scope). Your while loop might actually be compiled as if it was written:
while (myDictionary = [myArraytEnumerator nextObject])
{
[myDictionary objectForKey:[ParserXML parserObjectFieldName]];
[myDictionary objectForKey:kField_FactYear];
[myDictionary objectForKey:kField_FactMonth];
[myDictionary objectForKey:kField_FactDay];
[myDictionary objectForKey:kField_FactSourceDatabase];
[myDictionary objectForKey:kField_FactText];
myObjectCount++;
}
which would produce the debug-time problems you describe.
Make sure you're working with the Debug configuration of your app, not the Release configuration, and that you haven't accidentally turned on compiler optimizations in the Debug configuration. If that doesn't get you anywhere, you may have to add code to reference the variables, in order to keep their symbol information "alive" long enough to examine them in the debugger. Another approach is to NSLog the variables, which will keep them alive as well as display them in the run log window.
_______________________________________________
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