Note that there are some explanatory texts on larger screens.

plurals
  1. PORunning a loop on AddressBook - Received memory warning
    primarykey
    data
    text
    <p>I'm running this code in order to create an image contains the caller's name, and setting it to the specific contact, but while it runs, I get Received memory warning and it crashes...</p> <pre><code>-(void)RunActionInBlack{ //black bg - white text ABAddressBookRef addressBook; CFErrorRef error = NULL; addressBook = ABAddressBookCreate(); CFArrayRef array=ABAddressBookCopyArrayOfAllPeople(addressBook); ABRecordRef person; int len=CFArrayGetCount(array); for (int i = 0; i&lt;len; i++){ person = CFArrayGetValueAtIndex(array, i); details.text = [NSString stringWithFormat:@"Done. %d of %d contacts", i+1,len]; [act stopAnimating]; NSString *firstName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty); NSString *lastName = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty); if (firstName == NULL) { firstName = @""; } if (lastName == NULL ) { lastName = @""; } UIImage *im = [self addText:[UIImage imageNamed:@"black.png"] andText:[NSString stringWithFormat:@"%@ %@",firstName, lastName]]; NSData *dataRef = UIImagePNGRepresentation(im); ABPersonSetImageData(person, (CFDataRef)dataRef, &amp;error); [lastName release]; [firstName release]; [dataRef release]; CFRelease(dataRef); [im release]; } ABAddressBookSave(addressBook, &amp;error); CFRelease(array); CFRelease(addressBook); } </code></pre> <p>Creating the text:</p> <pre><code>-(UIImage *)addText:(UIImage *)img andText:(NSString*)txt{ UIImageView *imView =[[UIImageView alloc] initWithImage:img ]; UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, img.size.width, img.size.height)]; [tempView addSubview:imView]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, -100, img.size.width, img.size.height)]; [label setText:txt]; [label setFont:[UIFont boldSystemFontOfSize:160]]; [label setTextColor:[UIColor whiteColor]]; [label setTextAlignment:UITextAlignmentCenter]; [label setBackgroundColor:[UIColor clearColor]]; [label setNumberOfLines:10]; [tempView addSubview:label]; UIGraphicsBeginImageContext(tempView.bounds.size); [tempView.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); [label release]; [tempView release]; [imView release]; return finalImage; } </code></pre> <p>I don't have any memory leaks or something...</p> <p>I'm running those methods like: <code>[self performSelectorInBackground:@selector(RunActionInWhite) withObject:nil];</code></p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload