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 7568741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:59:59+00:00 2026-05-30T14:59:59+00:00

My question is very simple, I would like to know if the method CGImageSourceCreateWithData

  • 0

My question is very simple, I would like to know if the method “CGImageSourceCreateWithData” creates a new object copying the data I provide so that that I have to release it when I don’t need it anymore, or if it just creates a reference to the data I already have so that if I release it I will lose this data (and possibly have bad access errors).

The issue is related to using (__bridge CFDataRef) as the source data. Which let’s me use Core Foundation objects as toll-free in ARC mode.

Consider the following function (or method, not sure how it’s called):

- (void)saveImageWithData:(NSData*)jpeg andDictionary:(NSDictionary*)dicRef andName:(NSString*)name
{
    [self setCapturedImageName:name];

    CGImageSourceRef  source ;

    // Notice here how I use __bridge
    source = CGImageSourceCreateWithData((__bridge CFDataRef)jpeg, NULL);

    CFStringRef UTI = CGImageSourceGetType(source); 

    NSMutableData *dest_data = [NSMutableData data];

    // And here I use it again
    CGImageDestinationRef destination = CGImageDestinationCreateWithData((__bridge CFMutableDataRef)dest_data,UTI,1,NULL);

    CGImageDestinationAddImageFromSource(destination,source,0, (__bridge CFDictionaryRef) dicRef);

    BOOL success = NO;
    success = CGImageDestinationFinalize(destination);

    if(!success) {
        NSLog(@"***Could not create data from image destination ***");
    }

    // This only saves to the disk
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
    NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"ARPictures"];

    NSError *error;
    if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
        [[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error]; //Create folder

    NSString *fullPath = [dataPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.jpg", name]]; //add our image to the path

    [dest_data writeToFile:fullPath atomically:YES];


    self.img = [[UIImage alloc] initWithData:dest_data]; 
    self.capturedImageData = [[NSData alloc] initWithData:dest_data];

    //This is what im not sure if i should use
    CFRelease(destination);
    CFRelease(source);

}

My concern is about memory leaks or dealocating things I should not.

Thanks

  • 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-30T15:00:00+00:00Added an answer on May 30, 2026 at 3:00 pm

    You are doing it correctly. It does not actually matter whether these routines make copies or not. What matters is that you CFRelease what you “Create” (or “Copy”). Everything here looks correct. __bridge is appropriate when passing parameters because you’re not actually transferring the object from CF to Cocoa or vice versa. You’re just temporarily “bridging” (casting) it.

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

Sidebar

Related Questions

I know this is probably a very simple question but how would I do
Here's a very simple question. I have an SP that inserts a row into
This is probably a very simple question. I am new to Rails and have
I know this is a very simple question, but I'm having trouble finding the
My question is very simple: Is there any solution to install xCode, or equivalent,
Very simple question, is there any cloud server enviroments avaliable these days for us
Very simple question, I made the following program : #include <stdlib.h> int main(int argc,
Very simple question. What does the term 'seeding' mean in general? I'll put the
Maybe a very simple question. How can I put in this code <Query> <Where>
This is a very simple question with a simple answer, but it is not

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.