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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:36:57+00:00 2026-05-24T12:36:57+00:00

I have a UIScrollView in my UIViewController defined as this in my .h file:

  • 0

I have a UIScrollView in my UIViewController defined as this in my .h file:

#import <UIKit/UIKit.h>

@interface TestViewController : UIViewController <UIScrollViewDelegate>

@property (nonatomic, retain) UIScrollView * imageScrollView;

@end

Then in my .m file I have the following:

@synthesize imageScrollView = _imageScrollView;

I read that this will automatically create the _imageScrollView that I would normally type in the .h file? (UIScrollView * _imageScrollView)

I like it, because it removes duplicate code from my .h files. Now in my loadView I do the rest:

self.imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0 - 20.0 - 49.0)];
[_imageScrollView setDelegate:self];
[_imageScrollView setPagingEnabled:YES];
[_imageScrollView setBounces:NO];
[_imageScrollView setShowsHorizontalScrollIndicator:NO];
[_imageScrollView setShowsVerticalScrollIndicator:NO];
[_imageScrollView setContentSize:CGSizeMake(320.0 * 3.0, 480.0 - 20.0 - 49.0)];

And in the dealloc release and nil:

- (void)dealloc
{
[_imageScrollView release], _imageScrollView = nil;

[super dealloc];
}

Now after a build Xcode is telling me this:

Potential leak of an object allocated on line #linenumber

This will go away when I change this:

self.imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0 - 20.0 - 49.0)];

to this:

self.imageScrollView = [[[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0 - 20.0 - 49.0)] autorelease];

Why do I need to autorelease this when I’m release it in dealloc? What am I doing wrong?

This memory warning only occurs in Xcode on my iMac with Lion installed, not on my macbook with snow leopard…

  • 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-24T12:36:58+00:00Added an answer on May 24, 2026 at 12:36 pm

    It’s because your imageScrollView property is declared to be a retain property. This means that when you set it, the accessor (which is generated by @synthesize) automatically retains the value. If you don’t want this behavior, you should declare your property to be assign. (But you do want this behavior in this case.)

    Anyway, thus your object is retained twice, once in your code, and once by the accessor, so it’s never released. Always remember that self.imageScrollView = is just like [self setImageScrollView:], and that stuff happens in there!

    (And last, the memory warning only occurs on Lion because the old Xcode isn’t noticing the error, not because the error isn’t there.)

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

Sidebar

Related Questions

I have a simple ViewController that looks like this: @interface MyViewController : UIViewController<UIScrollViewDelegate> {
I have the following code: //RootViewController.h: #import <UIKit/UIKit.h> @interface RootViewController : UIViewController{ IBOutlet UITextField
I have a UIViewController subclass which has the view property set to a UIScrollView
Following Scenario: I have a = UIViewController A that contains a UIScrollView I have
I have a UIViewController, on top I put an UIImageView, then a UIScrollView. I
So I have a UIViewController subclass called MyTabBarViewController that has a UIScrollView. Inside of
I have a custom UIViewController subclass controlling a UISCrollView containing an UIImageView, set up
I have a UIViewController, which uses a UIScrollView and within that Scrollview it has
So I have things nested like this in a nib: UIViewController | |-UIView (container
At the moment I have a UIViewController subclass with a UIScrollView and a UIView

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.