CF address book memory issues

Marcus Wood <[email protected]>
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
Hi there,

I've been developing an application which needs to access the address  
book. The problem is I don't think Im properly releasing my CF objects  
and so I subsequently get old data

There is an abstracted piece of code to demonstrate my problem below,  
but basically it prints the first name in a loop. The problem being  
that when you update the first name in address book it still prints  
out the old name, leading me to think that the old memory isn't being  
released

Any help would be really appreciated, :)

Thanks,
Marcus


PS: if you are trying the code out and need an address book UID if you  
export a vCard and open it with a text editor you can find it in there


#include <CoreFoundation/CoreFoundation.h>
#include <AddressBook/ABAddressBookC.h>

#include <stdio.h>
#include <unistd.h>

int GetProperty(char *UIDStr, CFStringRef propertyConstant, char  
*retVal, uint retValSize)
{	
	CFStringRef			UID;
	CFStringRef			property;
	ABAddressBookRef		addrBook;
	ABRecordRef			record;
	
	
	UID = CFStringCreateWithCString(kCFAllocatorDefault, UIDStr,  
kCFStringEncodingMacRoman);
		
	addrBook = ABGetSharedAddressBook();
	
	record = ABCopyRecordForUniqueId(addrBook, UID);
		
	property = ABRecordCopyValue(record, propertyConstant);
		
	CFStringGetCString(property, retVal, retValSize,  
kCFStringEncodingMacRoman);

	
	CFRelease(property);
	CFRelease(record);	
	CFRelease(UID);
	
	return (TRUE);
}
		

int main (int argc, const char * argv[])
{
	char propertyStr[255];
	
	while(1)
	{
		GetProperty("14FA361C-17D4-48DE-808C-5DD10A9299CA:ABPerson",  
kABFirstNameProperty, propertyStr, sizeof(propertyStr));
		printf("propertyStr: %s\n", propertyStr);
		sleep(2);
	}
	
     return 0;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.