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

The Archive Base Latest Questions

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

I ran analyze on my 1st iPhone app, and I see a few potential

  • 0

I ran analyze on my 1st iPhone app, and I see a few potential memory leaks. The app itself works fine on the simulator.
I would like to do the right thing and clear the potential memory leaks, but some are quite puzzling. Maybe someone could help me here?

Thanks in advance.

Pier.

Error 1) The Analyzer says “Potential leak of an object stored in tempDate and tempAns”

#import "Answer.h"

@implementation Answer
@synthesize answerTiming; 
@synthesize xPosition; 
@synthesize earlyOrLate; 
@synthesize hit; 

+ (Answer *) createAnswerWithTiming :(NSDate *)paramTiming andXPosition :(float) xPosition
{
NSDate * tempDate = [[NSDate alloc] initWithTimeInterval:0 sinceDate:paramTiming];
Answer * tempAns = [[Answer alloc] init ];
[tempAns setAnswerTiming:tempDate];
[tempDate release];
[tempAns setXPosition:xPosition]; 
[tempAns setEarlyOrLate:0];
[tempAns setHit:false];

return tempAns; 
}


- (void)dealloc {
[answerTiming release];
[self release];
[super dealloc]; 
}

@end

Error 2) Analyzer says (see below)

- (void)viewDidLoad
{
[super viewDidLoad];

   ........
   ...

UIImage * perfectImage = [UIImage imageNamed: @"perfect.png"];
self.perfectImageView2 = [[UIImageView alloc]initWithImage:perfectImage]; 

// method returns an objective C content with a +1 retain count

[self.perfectImageView2 setFrame:CGRectMake(145.0f,
                                            150.0f,
                                            self.perfectImageView2.image.size.width,
                                            self.perfectImageView2.image.size.height)];

self.view.backgroundColor = [UIColor whiteColor];

UIImage * levelUpImage = [UIImage imageNamed:@"levelup.png"];
self.levelUpImageView = [[UIImageView alloc] initWithImage:levelUpImage];
[self.levelUpImageView setFrame:CGRectMake(100.0f,
                                            400.0f,
                                            self.levelUpImageView.image.size.width,
                                            self.levelUpImageView.image.size.height)];

//object leaked, allocated object is not referenced later in this execution path and has a retain count of +1

self.view.backgroundColor = [UIColor whiteColor];
}

Error 3)

- (NSMutableArray *) generateQuestionTapAnswers:(NSString *) answersString withFirstBeat:    (NSDate *) firstBeatTime
{
NSArray * notesToDraw = [answersString componentsSeparatedByCharactersInSet: [NSCharacterSet characterSetWithCharactersInString: @" "]];

float noteValueOffset = 0.0; 

NSMutableArray * answerArray = [[NSMutableArray alloc] init ];

// Method returns an objective C object with a +1 retain count

for (int i=1; i < notesToDraw.count; i++) // i = 0 is the time signature
{
 .....
}
return answerArray;

// Object returned to caller as an owning reference (single retain count transferred to caller)
// Object leaked: Object allocated and stored into answerArray is returned from a method whose name generateQuestionTapAnswers does not start with copy, mutableCopy
}

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

    Regarding your first and third warnings, the compiler will assume that you’ll be creating an object in “a method whose name begins with alloc, new, copy, or mutableCopy” (see Advanced Memory Management Programming Guide). So, if you’re returning a +1 object, make sure your method name begins with one of those four prefixes. If you create a +1 object without one of those prefixes, it won’t be happy. So, for error #1, if you rename that method to be something like newAnswerWithTiming, that warning should go away. (If the calling method doesn’t clean up after them, though, the warning will just be shifted to that routine, but let’s take it one step at a time.)

    Likewise for error #3, if you rename that method to be something like newAnswerArrayFromQuestionTapAnswers (or whatever … I’m not sure if I understand your method name … just make sure it starts with new), you’ll similarly eliminate that warning. In both cases, just make sure to release it at the appropriate point because whomever called these two respective methods now “owns” those objects and is responsible for their cleanup.

    As an aside, you don’t need to do [self release] in your dealloc in your discussion of error #1. (Frankly, I’m surprised it doesn’t generate an error.) You don’t need it because if self wasn’t already at retainCount of zero, you never would have gotten to dealloc in the first place.

    Regarding error #2, how are the properties perfectImageView2 and levelUpImageView defined? If retain or strong, you’re creating something with a +2 retainCount, and you probably want to add an autorelease after the alloc/init.

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

Sidebar

Related Questions

I ran the convert_to_south command on my app. Everything seems to have gone fine:
In Visual Studio 2008 Team System, I just ran Code Analysis (from the Analyze
Ran into a snag and hoping for some insight here. Overview: Universal app. The
I ran 'analyze in xcode on a current iOS project to try to track
I've ran Build and Analyze on my XML parsing code and found out the
Hi guys I ran the analyser on http://www.websiteoptimization.com/services/analyze/ and I got a number of
I've never considered this a problem, until I ran the Xcode Analyze feature. Say
I have a HotSpot JVM heap dump that I would like to analyze. The
I can write an app that would copy all input from cin into a
I am very new new to iPhone app development and not able to correct

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.