Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7543067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:19:53+00:00 2026-05-30T08:19:53+00:00

I have a strange problem while saving number of big images (from camera) to

  • 0

I have a strange problem while saving number of big images (from camera) to the filesystem one after another in loop.

If I place [NSThread sleepForTimeInterval:1.0]; in each loop, than memory is released just fine after every image processing. But without that sleep interval, memory allocation increases above the roof and eventually app crashes…

Could someone please explain how to avoid this or to deallocate memory after each loop?

Btw, I’m developing on iOS 5…

This is the my code:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    for (NSDictionary *imageInfo in self.imageDataArray) {

        [assetslibrary assetForURL:[NSURL URLWithString:imageUrl] resultBlock:^(ALAsset *asset) {
            CGImageRef imageRef = [[asset defaultRepresentation] fullResolutionImage];
            if (imageRef) {
                [sharedAppSettingsController saveCGImageRef:imageRef toFilePath:filePath];
                imageRef = nil;
                [NSThread sleepForTimeInterval:1.0];
                //CFRelease(imageRef);
            }
        } failureBlock:^(NSError *error) {
            NSLog(@"booya, cant get image - %@",[error localizedDescription]);
        }];

    }

    // tell the main thread
    dispatch_async(dispatch_get_main_queue(), ^{
        //do smth on finish
    });
});

And this is the method for saving CGImage to FS:

- (void)saveCGImageRef:(CGImageRef)imageRef toFilePath:(NSString *)filePath {
    @autoreleasepool {
        CFURLRef url = (__bridge CFURLRef)[NSURL fileURLWithPath:filePath];
        CGImageDestinationRef destination = CGImageDestinationCreateWithURL(url, kUTTypeJPEG, 1, NULL);
        CGImageDestinationAddImage(destination, imageRef, nil);

        bool success = CGImageDestinationFinalize(destination);
        if (!success) {
            NSLog(@"Failed to write image to %@", filePath);
        }
        else {
            NSLog(@"Written to file: %@",filePath);
        }
        CFRelease(destination);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:19:55+00:00Added an answer on May 30, 2026 at 8:19 am

    The problem is that you call “assetForURL” in a for loop. This method will begin loading all of your images simultaneously each on a separate thread. You should begin loading 1 image and in completion block continue with loading the next one. I suggest you use some kind of recursion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have quite a strange problem , While copying one WidgetCollection from one FlowPanel
I have a strange problem while trying to start JBoss from Eclipse. After starting,
Well I have a strange problem while convert from unix timestamp to human representation
after migrating from .NET 3.5 to 4.0 i have a strange problem with a
I have one strange problem, if I use graphics.lineTo while moving the mouse (
We have very strange problem, one of our applications is continually querying server by
We have a strange problem when implementing sessions with ColdFusion in IE6. After login
I have a strange problem while working with CCSprite subclass Creature. Lets,my object is
I have this very strange problem while compiling the project. MOC seems to be
I have a strange problem. while MicrosoftMvcValidation works in my mvc project, MicrosoftMvcJQueryValidation doesn't.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.