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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:24:31+00:00 2026-06-18T23:24:31+00:00

Well I have some troubles with initialisation class properties in objective c. I have

  • 0

Well
I have some troubles with initialisation class properties in objective c. I have read a lot information but I didn’t find answer to my question.
So I give example.
1)

//Ex_1.h
@interface Ex_1: UIView {
   IBOutlet UIButton *playBut;
}

@property(retain, nonatomic) IBOutlet UIButton *playBut;
-(void) method1;

@end

//Ex_1.m
@implementation Ex_1
@synthesize playBut;

-(id) initWithFrame:(CGRect)frame {
  self = [super initWithFrame : frame];
  if (self != nil)
      playBut = [UIButton buttonWithType:UIButtonTypeRoundedRect]; //retainCount of playBut = 1;
  return self;

}

-(void) method1 {
   [playBut setTitle:@"pause" forState:UIControlStateNormal];
}

@end

I main Programm first I init object of Ex_1 and then after some times call method1 of this object ([object method1]) and I get runtime error(error tells me that playBut is dealloc, but I think playBut’s retain count = 1).
So I have some questions:

  1. Is it possible ?
  2. Why garbage collector dealloces playBut if its retain count = 1?(because I don’t call [playBut release];
  3. How do I init class properties?

I familar with C++ and actionScript, but I see first time in my life that garbage collector dealloced class property.
I use non ARC.
It is important for me.
Thanks for your attention and answers.

  • 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-18T23:24:32+00:00Added an answer on June 18, 2026 at 11:24 pm

    [UIButton buttonWithType:] returns an autoreleased object. It will be alive for the lifetime of the scope in which you call it, i.e. initWithFrame: but the autorelease pool can reclaim it after that. You should instead say, in your init selector:

    playBut = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
    

    Then send this in your dealloc:

    [playBut release];
    

    Now, if you were to add the playBut as a child to another UIView, that view would retain the child and you wouldn’t need to, as long as you only use it during the lifetime of the super view. This is a normal pattern. You could go further and assign a tag to playBut then use viewWithTag: to find your UIButton when you need it.

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

Sidebar

Related Questions

I have some login code that works well for Firefox and other browsers, but
I have a State class that includes configuration as well as some state-specific methods.
Well, I have a application which somehow requires some system resources, but how do
I have some troubles in dealing with this search() function that i wrote. Well,
I am trying to understand Adaboost algorithm but i have some troubles. After reading
I'm encountering some troubles while trying to access some properties with parameters. Well, I
I have some non well-formed xml (HTML) data in JAVA, I used JAXP Dom,
I know java well, and have some experience in EclipseLink, Hibernate, JSF, Grails and
well i have a listbox with some items inside. i want to detect a
I have done some project in Irrlicht and it compiles all well, however when

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.