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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:56:31+00:00 2026-06-09T05:56:31+00:00

I have a NSMutableArray which is used inside the ASIHTTPRequest process. After the data

  • 0

I have a NSMutableArray which is used inside the ASIHTTPRequest process. After the data loading is done, the NSMutableArray stores the info. When I add the data as

[MyArray addObject];

I dont have any errors. However when I insert the data as

[MyArray insertObject:[UIImage imageWithData:data] atIndex:buttonTag];

I have malloc error or index out of range exception issues. I assume this as a thread safety malfunctioning. Any solution for this?

EDITED:
in appdelegate.h

 @interface{
  NSMutableArray *imageArray;
 }

in appdelegate.m

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
imageArray = [[NSMutableArray alloc] init];
return YES;
}

In the AsyncImageView.h

@interface{
  AppDelegate *delegate
}

AsyncImageView.m

- (void)connectionDidFinishLoading:(NSURLConnection*)theConnection {

  delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  [delegate.imageArray insertObject:[UIImage imageWithData:data] atIndex:buttonTag];

 }
  • 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-09T05:56:32+00:00Added an answer on June 9, 2026 at 5:56 am

    It’s hard to say without seeing your code, but I doubt this is a threading issue. When you call insertObject:atIndex: you have to be able to guarantee there are at least that many objects in the array already. Look at your code and see where you add objects, and make sure that every scenario leads to you adding enough objects that insertObject:atIndex won’t fail.

    Hopefully this next fact is obvious to you, but just in case, I’ll point out that initWithCapacity: does not add any elements to the array. Many people assume it does, leading to the exact problem you described.

    Based on your comment, the solution might be to pre-populate your array with a bunch of NSNull objects, or to use an NSDictionary instead of an array.

    EDIT
    Here’s a quick NSDictionary example:

    Upon further review, you’ll actually need an NSMutableDictionary since you’re dynamically updating its contents. You can’t use an integer as the key, so you have to “wrap” the integer in an NSNumber object. (Note that you can use any object as a key, not just NSNumbers.)

    Store an object like this:

    [myDictionary setObject:[UIImage imageWithData:data] forKey:[NSNumber numberWithInt:buttonTag]];
    

    Access it later like this:

    myImage = [myDictionary objectForKey:[NSNumber numberWithInt:buttonTag]];
    

    Of course, much more information is available in Apple’s documentation or with a quick search for “NSDictionary example.”

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

Sidebar

Related Questions

Please help me i have a NSMutableArray which contains data until viewDidLoad is finished.
In my aplication, I have an nsmutablearray which stores a number of types of
I have a custom class named Profile and a NSMutableArray which I add the
I have an NSMutableArray which has five objects in it. I want to insert
I have an NSMutableArray which I assign with: NSMutableArray *newElements = [[NSMutableArray alloc] initWithObjects:self.currentScene.elements,
Essentially I have an NSMutableArray which contains several NSDictionaries . I wish to sort
Here's my current situation: I have a NSMutableArray named dictKeyArray which I assign a
All. I have a NSMutableArray , which name is dummyPerson. And it's element is
I have a Singleton which has an NSMutableArray containing a Class, the Class contains
I have an NSMutableArray of names. I want the pass the data (selected name)

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.