Memory leak at NSObject allocation
Posted
by Srilakshmi Manthena
on Stack Overflow
See other posts from Stack Overflow
or by Srilakshmi Manthena
Published on 2010-03-23T11:05:12Z
Indexed on
2010/03/23
11:13 UTC
Read the original article
Hit count: 243
objective-c
HI, I am getting memory leak at NSObject allocation i.e.,
ContactDTO* contactDTO = [[ContactDTO alloc] init];
Code:
+(ContactDTO*) getContactDTOForId:(NSString*) contactId
{
NSString* homeMail =@"";
NSString* workMail=@"";
NSString *lastNameString=@"";
NSString *firstNameString=@"";
firstNameString = [AddressBookUtil getValueForProperty:kABPersonFirstNameProperty forContact:contactId];
lastNameString = [AddressBookUtil getValueForProperty:kABPersonLastNameProperty forContact:contactId];
ABRecordID contactIntId = [contactId intValue];
ABRecordRef person = ABAddressBookGetPersonWithRecordID(addressBook, contactIntId);
ABMultiValueRef emailMultiValue =(NSString *)ABRecordCopyValue(person, kABPersonEmailProperty);
for(CFIndex j=0;j<ABMultiValueGetCount(emailMultiValue);j++)
{
NSString* curentTypeLabel =(NSString *)ABMultiValueCopyLabelAtIndex(emailMultiValue,j);
if([curentTypeLabel isEqualToString:@"_$!<Home>!$_"]==YES)
{
NSString* currentEmail =(NSString *)ABMultiValueCopyValueAtIndex(emailMultiValue,j);
if([currentEmail isEqualToString:nil]==NO)
{
homeMail = [currentEmail copy];
}
}
if([curentTypeLabel isEqualToString:@"_$!<Work>!$_"]==YES)
{
NSString* currentEmail =(NSString *)ABMultiValueCopyValueAtIndex(emailMultiValue,j);
if([currentEmail isEqualToString:nil]==NO)
{
workMail = [currentEmail copy];
}
}
}
ContactDTO* contactDTO = [[ContactDTO alloc] init];
contactDTO.firstName = firstNameString;
contactDTO.lastName = lastNameString;
contactDTO.contactId = contactId;
contactDTO.homeEmail = homeMail;
contactDTO.workEmail = workMail;
return [contactDTO autorelease];
}
© Stack Overflow or respective owner