Re: [NSMutableDictionary setObject:forKey:] problem
Re: [NSMutableDictionary setObject:forKey:] problem
- Subject: Re: [NSMutableDictionary setObject:forKey:] problem
- From: Elias MÃ¥rtenson <email@hidden>
- Date: Thu, 20 Oct 2005 00:15:01 +0200
19 okt 2005 kl. 23.49 skrev Joachim:
[ lots of code snipped ]
[albumDict
setObject:[[NSDictionary alloc]
initWithObjectsAndKeys:
[[iPhotoAlbumDict objectForKey:@"AlbumId"]
copy], @"AlbumId",
[[iPhotoAlbumDict objectForKey:@"Album Type"]
copy], @"AlbumType",
[[iPhotoAlbumDict objectForKey:@"PhotoCount"]
copy], @"PhotoCount",
nil]
forKey:[iPhotoAlbumDict
objectForKey:@"AlbumName"]];
I can't tell you why the element don't get added, but you have an
object leak here. NSDictionary retains whatever is inserted into it,
and you're not releasing your value. You should probably put in an
autoreleased instance, allocated with [NSDictionary
dictionaryWithObject:x forKey:y];
Here's my questions:
1) What's wrong with my code above? Why isn't the NSDictionary
object added with the setObject:forKey: call?
Like I said, I'm afraid I can't tell you that.
2) Why does [iPhotoAlbumDict respondsToSelector:@selector
(objectForKey)] always return false? ([iPhotoAlbumDict class]
returns NSCFDictionary.)
I believe the name of the selector is "objectForKey:", not
"objectForKey".
3) Am I handling memory correctly in my code? No leaks etc? I'm
still struggling to understand how Objective-C memory management
works.
Like I mentioned earlier, you do seem to have a memory leak.
Finally, does NSDictionary read the whole file into memory in the
initWithContentsOfFile: call or does it just scan the file later at
the given entry levels I specify in my code? The AlbumData.xml file
can get quite big, but I don't want to use NSXMLParser as it
involves way too much code.
I'm pretty sure it scans the entire file. It's only loaded at one
occasion. Besides, there is no index in the plist files.
_______________________________________________
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