0

I have a basic implementation for iCarousel where I am pulling images from a core-data store. I am experiencing memory related crashes when you get a lot of images loaded, as I guess is expected. The problem is I don't know of any way to use the AsyncImageView library since there is no NSURL reverence for a core-data object. Anyone know another way to manage this memory issue?

Here is my iCarousel viewForItemAtIndex

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{

    JournalEntry *journalEntry = (JournalEntry *)[fetchedResultsController objectAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0]];

    if (view == nil)
    {
        view = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 240.0f, 240.0f)] autorelease];
        view.contentMode = UIViewContentModeScaleAspectFit;
    }

    [((UIImageView *)view) setImage:[journalEntry.image valueForKey:@"image"]];

    NSLog(@"%i", index);

    return view;
}

For reference here is code for adding images to my core-data store straight out of the iPhoneCoreDataRecipes sample code.

@implementation ImageToDataTransformer


+ (BOOL)allowsReverseTransformation {
    return YES;
}

+ (Class)transformedValueClass {
    return [NSData class];
}


- (id)transformedValue:(id)value {
    NSData *data = UIImagePNGRepresentation(value);
    return data;
}


- (id)reverseTransformedValue:(id)value {
    UIImage *uiImage = [[UIImage alloc] initWithData:value];
    return [uiImage autorelease];
}

@end
3
  • Can you place a piece of code relating to the issue? Mar 12, 2013 at 4:19
  • Using AsyncImageView wouldn't be hard, but depending on how you're dealing with Core Data it might not help. It would be useful to know (a) what the Core Data entity that stores the image looks like, and (b) what your code to provide those images to iCarousel looks like (probably your -carousel:viewForItemAtIndex:reusingView:, but really wherever you're getting images from your Core Data entity). Mar 12, 2013 at 18:30
  • Added code for both comments. Thanks for the help.
    – Aaron
    Mar 13, 2013 at 0:15

1 Answer 1

0

After studying this for a while it turns out the large memory growth is due to the coredata cache and not iCarousel. This can be cleared by calling reset on the managedObjectContext.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.