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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:19:17+00:00 2026-05-26T09:19:17+00:00

with this code, i want to add an image at the place the user

  • 0

with this code, i want to add an image at the place the user taps. i want to add a new one for each tap.

-(void) foundDoubleTap:(UITapGestureRecognizer *) recognizer
{       
    UIView *piece = recognizer.view;
    CGPoint locationInView = [recognizer locationInView:piece];

    UIImageView *testPoint = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"inner-circle.png"]];
    testPoint.frame = CGRectMake(0, 0, 20, 20);
    testPoint.center = CGPointMake(locationInView.x, locationInView.y);
    [self.imageView addSubview:testPoint];

    NSMutableArray *tempTestPointArray = [[NSMutableArray alloc] initWithArray:testPointArray];
    [tempTestPointArray addObject:testPoint];
    testPointArray = tempTestPointArray;

    NSLog(@"testPointArray: %@", testPointArray);

    CGRect myRect = CGRectMake((testPoint.center.x + 12), (testPoint.center.y + 12), 10, 10);

    UILabel *myLabel = [[UILabel alloc] initWithFrame:myRect];
    myLabel.text = [NSString stringWithFormat:@"Point %d", [testPointArray count]];
    myLabel.font = [UIFont fontWithName:@"Trebuchet MS" size:10];
    [myLabel sizeToFit];
    [imageView addSubview:myLabel];
    [myLabel release];

    [testPoint release];
    //[tempTestPointArray release];
}

why is it that when i release tempTestPointArray, my code breaks when i implement a second tap? it crashes on:

NSMutableArray *tempTestPointArray = [[NSMutableArray alloc] initWithArray:testPointArray];

when i comment out the release for it, the Analyzer does not flag it as a leak. what happened to the rule, if you alloc/init it, you have to release it?

EDIT: adding .h file

.h file:

@interface TestPointMapViewController : UIViewController <UIScrollViewDelegate, UITextFieldDelegate>
{
    //other code
    NSArray *testPointArray;
}
//other code
@property (nonatomic, retain) NSArray *testPointArray;
//other code
@end

and then @synthesize testPointArray in .m file.

  • 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-26T09:19:18+00:00Added an answer on May 26, 2026 at 9:19 am

    Your testPointArray is not assigning to a property, it is a plain ivar. Doing the line

    testPointArray = tempTestPointArray;
    

    Is leaking whatever is previously in testPointArray. Declare testPointArray as a retained property and change to.

    self.testPointArray = tempTestPointArray;
    

    Then keep the [tempTestPointArray release];

    EDIT:

    So the reason why this code is failing has to do with the magic of properties. The following code is equivalent.

    self.testPointArray = tempTestPointArray;
    [self setTestPointArray:tempTestPointArray];
    

    When you do the @sythesize testPointArray; it is generating a setter method similar to this:

    - (void)setTestPointArray:(NSMutableArray *)array {
        id temp = testPointArray;
        testPointArray = [array retain];
        [temp release];
    }
    

    So when you don’t use the property notation self.testPointArray you are not retaining the variable correctly. You are also losing a reference to a retained object, which is now a leak.

    That make sense? If not please review this.

    http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/objectiveC/Chapters/ocProperties.html#//apple_ref/doc/uid/TP30001163-CH17-SW1

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

Sidebar

Related Questions

I want to add an image to TabHost . This is my code: tabHost.addTab(tabHost.newTabSpec(tab1).setContent(new
I want to add a new image view at the location where user touch
I want to add this code: <link rel=stylesheet type=text/css href=css/global.css /> <!--[if lt IE
i have this javascript code to which i want to add the jquery fade-in
I'm new to PHP and I want this code <option value= disabled=disabled>-------------</option> to be
I have this code that I want to make point-free; (\k t -> chr
according to this code if i want to access imageView1 and imageView2 how can
I have a question concerning this code which I want to run on QNX:
This code selects the nodes, I want to work on...: <xsl:variable name=rootTextpageNode select=$currentPage/ancestor-or-self::node [@level
In this particular code sample I want to reference the second overloaded method (int

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.