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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:25:38+00:00 2026-05-18T11:25:38+00:00

The Leaks instrument is sounding the alarm on some code, but I don’t know

  • 0

The Leaks instrument is sounding the alarm on some code, but I don’t know how to address the leak without crashing the app. Here’s some code summarizing my approach, written some time ago and clearly in need of rethinking:

labels = [[NSMutableArray alloc] init];

for(int i = 0; i < 10; i++) {
    // calculate x and y...
    label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, 70, 15)];
    // customize label...
    [labels addObject:label];
    [label release];
    [self addSubview:[labels objectAtIndex:i]];
}

Why bother with the labels NSMutableArray? Later, in other methods, I need to change the alpha of the labels, and it’s convenient to be able to say

[[labels objectAtIndex:num] setAlpha:0.5];

I believe the leak occurs because labels doesn’t get dealloc’ed during the normal app lifecycle, only when the superview is dealloc’d at quit.

Help!

Thanks.

  • 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-18T11:25:39+00:00Added an answer on May 18, 2026 at 11:25 am

    It’s probably happening because you’re not dealloc’ing the labels array. What about releasing the labels array after the for loop, then using .tag to set the label on the UIView and find the label later via the .tag using viewWithTag to setAlpha?

    labels = [[NSMutableArray alloc] init];
    
    for(int i = 0; i < 10; i++) {
        // calculate x and y...
        label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, 70, 15)];
        label.tag = 100;
        // customize label...
        [labels addObject:label];
        [label release];
        [self addSubview:[labels objectAtIndex:i]];
    }
    
    [labels removeAllObjects];
    [labels release];
    

    Then later

    (UILabel*) [[self.view viewWithTag:100] setAlpha:0.5];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to clean my app from leaks with Leak instrument. It shows me
My code leaks but I do not know exactly what am I doing wrong.
I'm having some trouble with Instruments. My app is working perfectly without crashes, but
The Leaks Instrument in Xcode shows me an memory leak here. I have commented
See the screenshot below, this is the only leak the Leaks Instrument finds in
I've removed few release from my code to see if Leaks instrument in xCode
Did a test on instrument and found memory leak for this piece of code
Related to this question: Memory leak tool tells me zero leaks but memory footprint
I am using the leak instrument first time. i am getting two leaks in
Do you know what may cause memory leaks in JavaScript? I am interested in

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.