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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:08:49+00:00 2026-06-13T02:08:49+00:00

I have nearly 45 UIButton s in my view, i know that the buttons

  • 0

I have nearly 45 UIButtons in my view, i know that the buttons have not been allocated to the memory, somehow the compiler alloc/release it, but i noticed that the device become slower at this view, so… What should i do to avoid memory leek with the UIButton ??

Here is how i put my buttons into my view:

in myView.h:

UIButton *btn1;

in myView.m :

btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
[btn1 setTitle:@"btn1" forState:UIControlStateNormal];
[btn1 addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
btn1.backgroundColor = [UIColor clearColor];
btn1.frame = CGRectMake(  arc4random() % 920, arc4random() %600+50  , 65, 65);
[self.view addSubview:btn1];

and how i remove it:

for(UIButton* b in [self.view subviews]){
    [b removeFromSuperview];
    b = nil;

}
  • 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-13T02:08:50+00:00Added an answer on June 13, 2026 at 2:08 am

    Memory leaks by themselves will not produce a significant slow-down of your app. Their effect is filling up the memory and, if in sufficient number, the operating system will kill your app due to excessive memory use. (If the operating system did not kill your app, then you could have a slow down, but since it kills the app, no issue).

    In any case, if you are worried by memory leaks, you could fire Instruments and see whether it detects any memory leaks when your view is displayed.

    Possibly the reason why you view is slow is that is has to load into memory 45 images, reading them from disk (which is slow). You might think of pre-loading them, and see if this improves things.

    An easy way to preload an image is to instantiate it through imageNamed:

     UIImage* img = [UIImage imageNamed:@"myButton1.png"];
    

    You could call that method for all of your buttons and collect all the relevant calls in another method that you could call, e.g., at startup, or at any other moment when it makes sense for you.

    EDIT:

    when i enter the view and exit and reenter the view and so on

    Just a note: you do not need to remove the buttons from their superview (in normal conditions): this will be done by the framework when removing the superview. Could be this that is slowing down the app?

    Besides, if the problem happens when exiting/entering the view, could you try and “cache” the whole view (like: instantiating it just once, then displaying it when it is needed).

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

Sidebar

Related Questions

I have read nearly every single post about the activity not found to handle
I have been building a game for a while (nearly done) - But the
i have been banging my head for the solution for nearly 14 hours and
I have a couple classes that have nearly identical code. Only a string or
In a recent project I have nearly completed we used an architecture that as
I have nearly 100 HTML files that uses the <tt> tag to markup inline
I have nearly completed my .htaccess file now so that my urls all work
I have nearly successfully made a query for MySQL via Python that shows the
I have nearly tried everything but cannot figure out what is wrong. I have
I have nearly finished a free spellchecker library for Windows Mobile, and there are

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.