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

  • Home
  • SEARCH
  • 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 9199231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:29:10+00:00 2026-06-17T22:29:10+00:00

I currently am using the code I found on an online tutorial to have

  • 0

I currently am using the code I found on an online tutorial to have the iPhone user select an image from their camera roll. Setting the image to the UIImageView works fine, but then I try to call a function on the image (every time a slider is moved). It turns out that the operating system is not holding onto the image, so when I try to access it (or the caching variable I made), it doesn’t work (because the address gets set to 0x0000000).

If UIImage conformed to NSCopying, this would be simple. But, it doesn’t. So, how do I copy an image so the operating system doesn’t delete it?

Possible Duplicates

  • How do I make an exact copy of a UIImage returned from a UIImagePickerController?
  • Making deep copy of UIImage

EDIT:
The slider, when changed, calls this function:

- (IBAction)samplingSliderChanged:(id)sender {
    NSLog(@"%@", self.imageStay);
    float sample = self.samplingSlider.value * 0.6 + 0.2;
    self.samplingRateText.text =  [NSString stringWithFormat:@"%.0f%%", sample*100];
    //self.imageView.image = [self.brain sampleImage:self.imageStay atRate:sample];
    self.imageView.image = [self.brain sampleImage:self.imageStay.copy atRate:sample];
    NSLog(@"self.imageStay: %@, self.imageStay.copy: %@", self.imageStay, self.imageStay.copy);
}

The first time the slider is moved, my self.imageStay (the cache variable) has an address of 0x0000.

My show-the-camera-roll function is below:

-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSString *mediaType = info[UIImagePickerControllerMediaType];
    UIImage * image;
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
    image = info[UIImagePickerControllerOriginalImage];
    image = [self imageWithImage:image scaledToSize:CGSizeMake(256, 256)];
    self.imageView.image = image;

    if (_newMedia)
        UIImageWriteToSavedPhotosAlbum(image,
                                       self,
                                       @selector(image:finishedSavingWithError:contextInfo:),
                                       nil);
    self.imageView.image = image;
    self.imageStay = image


}

In here, the cache variable has the same memory address as image, and my guess is that this later gets deleted.

  • 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-06-17T22:29:12+00:00Added an answer on June 17, 2026 at 10:29 pm

    You shouldn’t be worrying about NSCopying, or making a copy of a UIImage, this isn’t your problem. You are losing the reference to the image in your imageView. The OS is holding onto the image, if not it would disappear from your imageView. I expect you just aren’t referring to it correctly. Perhaps you should show what you mean by a ‘caching variable’…

    In any case a reliable way to get to the image currently displayed in your imageView is to obtain it from the imageView’s image property, as self.imageView.image.

    update

    If self.imageView.image might be subject to filtering, and you also need to keep a reference to the original image (eg in self.imageStay) you should declare the imageStay property as

    @property (nonatomic, strong) UIImage* imageStay;
    

    If you have done this correctly, and still have a nil reference in self.imageStay, step through your code in the debugger to see what is going on here:

       self.imageView.image = image;
    
        if (_newMedia)
            UIImageWriteToSavedPhotosAlbum(image,
                                       self,
                                       @selector(image:finishedSavingWithError:contextInfo:),
                                       nil);
        self.imageView.image = image;
        self.imageStay = image
    

    self.imageStay and self.imageView.image should now both have a reference to the same object. By the way, you second assignment of self.imageView.image = image here is redundant.

    Then in - (IBAction)samplingSliderChanged:(id)sender you should find those references persisting.

    Your problem might be caused if you have declared your @property imageStay as a weak reference. It should be strong to ensure that it persists.

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

Sidebar

Related Questions

I am currently using this code to get data from a URL: NSURL *url
I am currently using code similar to this: try { // IE ONLY var
I'm currently using this code (per the codex) to show children on parent pages,
I'm currently using this code to calculate the sunrise / sunset times. (To be
I am currently using this code to grab key-strokes, but I am missing e.g.
I am currently using this code to bring up an info window -(IBAction)showInfo:(id)sender {
I am a rank beginner in C#. I am currently using this code: objGraphics.Clear(SystemColors.Control);
currently i using this code in phonegap application var xmlhttp = new XMLHttpRequest(); xmlhttp.open(GET,http://192.168.1.19:8080/searchMobile?categoryRequest=true,
I am currently using the following code to update form data before submission. $('.countyx').change(function(){
I'm currently using the validation code listed here in an application. I'd like to

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.