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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:33:45+00:00 2026-05-26T09:33:45+00:00

I have a class that mimics the behavior of the UIImagePickerController except with some

  • 0

I have a class that mimics the behavior of the UIImagePickerController except with some subtle differences. In my class, I use only one view controller and use it to swap out the albums tableview and photos tableview when the user makes a row / thumbnail selection. So the sequence of events that is causing me problems is as follows:

  1. I select an album
  2. The photos tableview loads, and I push the back button to go back
    to the albums tableview
  3. The albums tableview loads
  4. I select an album, and now a memory access error triggers

I have implemented both of the tableviews and the array in ivars as follows:

@property (nonatomic, retain) UITableView *selectAnAlbumTableView, *selectAPhotoTableView;
@property (nonatomic, retain) NSMutableArray *albums, *photos;
@property (nonatomic, retain) ALAssetsGroup *album;
@property (nonatomic, retain) UIActivityIndicatorView *spinner;

One difference between the albums tableview and the photos tableview is that the photos tableview is recreated each time a user selects an album and this is where the error occurs. Initially, the “EXC_BAD_ACCESS” was occurring when I was removing the tableview, like I do here:

        [[self selectAPhotoTableView] removeFromSuperview];
        [selectAPhotoTableView release];
        selectAPhotoTableView = nil;
        [photos release];
         photos = nil;

I noticed the error is occurring at [photos release]. Photos is the array where I store all of the thumbnail buttons that are put in cells on the photos tableview. If I remove [photos release] and photos = nil, then the problem occurs when the tableview is actually created (as I mentioned initially):

NSMutableArray *photosTemp = [[NSMutableArray alloc] init];
[self setPhotos: photosTemp];
[photosTemp release];

Now the “EXC_BAD_ACCESS” is being thrown after the [self setPhotos: photosTemp]; line. Does anyone know what I’m doing wrong here?

UPDATE: I put the wrong code for where the error occurs the second time, now it’s fixed.

  • 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-26T09:33:45+00:00Added an answer on May 26, 2026 at 9:33 am

    I’ll put this in an answer rather than a massive comment.

    This line (see comments) will cause a problem:

    thumbnailImage = [UIImage imageWithCGImage:[theALAsset thumbnail]]; 
    

    That’s becausethumbnailImageis an ivar.UIImage imageWithCGImageis returning you an autoreleased object. Therefore you must retain it either explicitly, as follows:

    thumbnailImage = [[UIImage imageWithCGImage:[theALAsset thumbnail]] retain]; 
    

    Or, you can let your property do it for you via the generated setters. Setting up a property as follows won’t do anything because in your line above you are referring tothumbnailImagedirectly, not via the setters.

    @property (nonatomic, retain) UIImage *thumbnailImage;
    

    What you need to do is useself, so you have:

    self.thumbnailImage = [UIImage imageWithCGImage:[theALAsset thumbnail]]; 
    

    That will go through generated setters that first checking for any existing object,releaseit if there is one, then do aretainon your newly assigned object. All that happens automatically. In other words, it saves you the bother of doing:

    -(void)setThumbnailImage:(UIImage *)aThumbnailImage
    {
        [aThumbnailImage retain];
        if (thumbnailImage)
        {
            [thumbnailImage release];
        }
        thumbnailImage = aThumbnailImage;
    }
    

    Aaron Hillegass’ book has a great explanation of this stuff in “Cocoa Programming for Mac OS X”.

    A key thing to do is to run builds with the Analyzer, or just run the Analyzer from time to time. It will spot a lot of these issues before you get to the time consuming process of tracking down EXC_BAD_ACCESS errors.

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

Sidebar

Related Questions

I have a class that I want to use to store properties for another
I have created a class, MonitoredCollection<T> , that basically encapsulates/mimics List but allows me
I have class that represents users. Users are divided into two groups with different
I have class method that returns a list of employees that I can iterate
I have a class that map objects to objects, but unlike dictionary it maps
I have a class that I wish to expose as a remote service using
I have a class that looks like this public class SomeClass { public SomeChildClass[]
I have a class that creates several IDisposable objects, all of these objects are
I have a class that encapsulates tcp socket communications with a server. For each
I have a class that processes a 2 xml files and produces a text

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.