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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:43:55+00:00 2026-05-26T01:43:55+00:00

I have a viewcontroller, into this I add a several subviews to his view,

  • 0

I have a viewcontroller, into this I add a several subviews to his view, add in array(array – its property of parent viewcontroller) and didn’t release subviews to add now, but release their in dealloc. I am embarrassed by messages about memory leaks. How can I find any way to solve problem with memory management? Thanks!

-(void)someMethod
{
    for(<<something in something>>)
    {
            ValidationColumnViewController *controller = [[ValidationColumnViewController alloc] initWithFrame:CGRectMake(columnsInitialX, 5, validationColumnWidth, validationColumnHeight) andValidationColumn:column withMaxCellsCount:maxCellsCountForValidationColumns];               
            [gameFieldView addSubview:controller.view];
            [validationColumnViewControllers addObject:controller];
    }
}
-(void)dealloc
{
    for(ValidationColumnViewController *controller in validationColumnViewControllers)
    {
        [controller release];
    }
}
  • 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-26T01:43:56+00:00Added an answer on May 26, 2026 at 1:43 am

    You should definitely release the objects you create with the line

    ValidationColumnViewController *controller = [[ValidationColumnViewController alloc] initWithFrame:CGRectMake(columnsInitialX, 5, validationColumnWidth, validationColumnHeight) andValidationColumn:column withMaxCellsCount:maxCellsCountForValidationColumns];
    

    Just after you add them to the array (the addObject: call increases the object’s retain count by 1), not in the dealloc. If you don’t they might be removed from the array before the dealloc by some other call and in that case, you’ll leak memory. I think you should also release validationColumnViewControllers in the dealloc method given it is apparently a retained ivar.

    Also adding the controller.view object to another view:

    [gameFieldView addSubview:controller.view];
    

    is not a good idea, this increases the controller.view retain count by 1 but not the controller retain count. This means the controller could be deallocated but not its view which will lead to problems (EXEC_BAD_ACCESS when the view tries to talk to its controller).

    Also in

    -(void)dealloc
    

    you should always call [super dealloc] at the end of the function, this is what actually causes the object to be deallocated.

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

Sidebar

Related Questions

How you can add a child ViewController into Master View Controller ? I have
I have a custom viewController called SourceListViewController, and I'm adding it into a UINavigationController,
I have view controller, into the view i have put a table view, and
I have a viewController (Planner) that loads two view controllers (InfoEditor and MonthlyPlan) when
I have a ViewController that has its own NIB. I would like to embed
consider the following scenario: I have a storyboard-based app. I add a ViewController object
I have a ViewController (with a MKMapView) which is pushed into, because of the
I have the navigationcontroller based viewcontroller and I overriding the root view controller navigation
The documentation says This method is called after the view controller has loaded its
I have a UIViewController that allow me to display some text into a view.

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.