On 05/03/2010, at 10:48 AM, Daniel Káčer wrote:

> a add my custom object into NSDictionary variable in my application with 
> following code:
> 
> [myDictionary setObject:[[ComplexObject alloc] initWithFrom:_tempFrom 
> pairTo:string] forKey:[NSString stringWithFormat:@"%d", [myDictionary 
> count]]];
> 
> .. it seems, that this work correctly ..

Except it's leaking. Don't put the alloc...init inside another statement. For 
one thing, if it fails you'll throw instead of continue. But more importantly, 
you don't have a reference to the object to release it once the dictionary has 
taken ownership, so it leaks.

> but .. when i will retrieve value from my custom object from this 
> NSDictionary variable, there is some issue ... and i don't know, what i do 
> wrongly in this case ...
> 
> int iRandom = arc4random() % ([myDictionary count] - 1);
> ComplexObject* compObj = [myDictionary objectForKey:[NSString 
> stringWithFormat:@"%d", iRandom]];
> NSString* sText = [compObj valueFrom];   <--- on this line is some issue

Well, what is the issue?

> - (ComplexObject*)initWithFrom:(NSString*)_sValueFrom 
> pairTo:(NSString*)_sValueTo {
>    self = [super init];
> 
>    if (self) {
>        sValueFrom = _sValueFrom;
>        sValueTo = _sValueTo;
>    }
>    return self;
> }

Simply assigning the strings to the ivars is inadequate. You also need to 
retain them, so I'm guessing the 'issue' is that you get an EXC_BAD_ACCESS 
because the returned references are stale.

You need to read this. Take three times a day every four hours.

http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html

Also, your naming conventions and use of underscores is all over the place.

--Graham


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to