Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-24-2009, 02:44 AM   #1 (permalink)
New Member
 
Join Date: Nov 2008
Posts: 10
ifonenewbie is on a distinguished road
Unhappy ABMultiValueRef memory leak

I'm trying to access just the email ID's of contacts and since there could be multiple emails, I'm using ABMultiValueRef


Here's my code:


- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPersonABRecordRef)pe rson
propertyABPropertyID)property identifierABMultiValueIdentifier)identifier{


ABMultiValueRef emails = ABRecordCopyValue(person, property);
CFStringRef emailID = ABMultiValueCopyValueAtIndex(emails, identifier);

[self AddEmployeeEmailNSString*)emailID ];

[self dismissModalViewControllerAnimated:YES];

return NO;
}


If I run this code through Leaks, it complains about a memory leak which i could resolve by '[emails release]', but this gives me a compiler warning. I've seen some posts about certain leaks happening on the simulator but not on the device. Could this be one of them??

Any suggestions ??
ifonenewbie is offline   Reply With Quote
Old 02-24-2009, 04:12 AM   #2 (permalink)
Registered Member
 
Join Date: Sep 2008
Location: London, UK
Posts: 1,050
wuf810 is on a distinguished road
Default

Quote:
Originally Posted by ifonenewbie View Post
I've seen some posts about certain leaks happening on the simulator but not on the device. Could this be one of them??

Any suggestions ??
If definitely could be. Try running launching and running your app with instruments on the iPhone itself. If the leak occurs then at least you know it is not just a simulator issue.

Good luck.

M
wuf810 is offline   Reply With Quote
Old 02-25-2009, 11:27 AM   #3 (permalink)
New Member
 
Join Date: Nov 2008
Posts: 10
ifonenewbie is on a distinguished road
Red face

OK, it leaks on the device too.

Is there another way to copy the email when there are multiple emails? I tried using

NSString* emails = (NSString*)ABRecordCopyValue(person, KABPersonEmailProperty);

but that isn't working either.

If I try this, I get a message saying the 'variable isn't a CFString at this time'

CFString emails = ABRecordCopyValue(person,property);

Does anyone have a working sample which doesn't leak
ifonenewbie is offline   Reply With Quote
Old 02-25-2009, 07:49 PM   #4 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 188
jsonli is on a distinguished road
Default

I'm not familiar with the CF stuff so I can't help you off the bat, but look up what ABRecordCopyValue is actually doing. Hold alt and double click it.

NSString and CFString shouldn't be interchangeable.

The variable emails doesn't look to be derived from NSObject so you should not be calling release on it if I'm correct.

In C you use malloc to allocate memory, and free to free it. Perhaps you should use free?
jsonli is offline   Reply With Quote
Old 02-25-2009, 11:34 PM   #5 (permalink)
Registered Member
 
Join Date: Sep 2008
Location: Denver
Posts: 172
BSDimwit is on a distinguished road
Default Try this...

Code:
CFStringRef email, emailLabel;

ABMutableMultiValueRef multi = ABRecordCopyValue(person, kABPersonEmailProperty);
NSMutableDictionary *myEmailDict = [NSMutableDictionary dictionaryWithCapacity:ABMultiValueGetCount(multi)];
for (CFIndex i = 0; i < ABMultiValueGetCount(multi); i++) { 
	
	emailLabel = ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(multi, i));
	email = ABMultiValueCopyValueAtIndex(multi, i); 
	[myEmailDict setObject:(NSString*)email forKey:(NSString*)emailLabel];
	CFRelease(email);
	CFRelease(emailLabel);
	
} 

if ([myEmailDict objectForKey:@"work"] != nil) {
	[self AddEmployeeEmail:[myEmailDict objectForKey:@"work"]];
}
Here is how I roughly do it in my code. I put the results in a dictionary that which ups the retain count by 1 then I release the address and the label... Let me know how this work out for you.
BSDimwit is offline   Reply With Quote
Reply

Bookmarks

Tags
abmultivalueref, leak

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 330
4 members and 326 guests
guusleijsten, HowEver, LEARN2MAKE, mottdog
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,880
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:43 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0