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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:48:35+00:00 2026-05-22T00:48:35+00:00

I am using a Nib as a template for several buttons. It seemed to

  • 0

I am using a Nib as a template for several buttons. It seemed to work fine, they each have their own independent state. However when I went to release the buttons I would crash in the dealloc. Here is the code…

mSoundBtns = new cSoundButton*[mNumSounds];
for(unsigned int i = 0 ; i < mNumSounds; ++i) {
    mSoundBtns[i] = nil;
}

for(unsigned int s = 0; s < mNumSounds; ++s) {

    [[NSBundle mainBundle] loadNibNamed:@"InstanceSoundButton" owner:self options:nil];
    //Auto Loads via Outlet into 'soundNib'

    mSoundBtns[s] = soundNib;
    soundNib = nil;

    uint32 count = mSoundBtns[s].retainCount;
    NSLog(@"Last Count: %d", count);
}


for(unsigned int j = 0; j < mNumSounds; ++j) {
    [mSoundBtns[j] release];  //**** Crash here on 7th (of 8) release
    mSoundBtns[j] = nil;
}

Header:

@interface cLocationContext {
   ...

   cSoundButton** mSoundBtns;
   IBOutlet cSoundButton* soundNib;

}

@property (nonatomic, assign) IBOutlet cSoundButton* soundNib;

@end

The Nib is very simple, it just include a parent view and a child view of a custom view type.
Nib

cSoundButton simply keeps track of a name and a boolean state Mute or Not. Here is the dealloc

- (void)dealloc {

    delete[] mSoundTag;

    // Call the inherited implementation
    [super dealloc];  //****Crashes in here
}

The crash is inside the call to super dealloc, in UIButton -> UIButtonContent dealloc. I assume I am doing something poor with my memory management like deallocing twice but I can’t spot where.

Is what I am doing by loading the nib multiple times legal?

  • 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-22T00:48:36+00:00Added an answer on May 22, 2026 at 12:48 am

    You have to retain the button as soon as you load it from the NIB. If you don’t, you are not allowed to release it later, and you won’t be able to access the button once your code returns control to the runloop (when the autorelease pool is drained).

    PS: Wouldn’t it be easier to use a Cocoa collection (NSMutableArray) to store the references to the buttons? Your code looks too complicated to me.

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

Sidebar

Related Questions

I know nib files are serialized objects and they have owner, outlets to make
I am using Xcode's SplitView template. I have changed the rootviewcontroller to be a
I have a UITableView, where I'm adding data to a row using a nib
Using online interfaces to a version control system is a nice way to have
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
I am creating an iphone app and wanted to know if using NIB files
For instance: Create a new UIVC using initWithNibName, using nib-v1 Display it, e.g. using
I have an image displayed using CGRect (code below). the problem is that it's
I have a UIImageView that I dynamically load with an Image using myTableViewCell.myImageView.image =
Has anyone got EclipseLink MOXy (I'm using eclipselink 2.1.0) to work with Java 5?

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.