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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:24:11+00:00 2026-05-26T03:24:11+00:00

Please see following code I want to know how can I de-alloc cell .

  • 0

Please see following code I want to know how can I de-alloc cell . From what I have understood there must be a de-alloc for every alloc and release for every retain.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"UITableViewCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc]
                 initWithStyle: UITableViewCellStyleSubtitle
                 reuseIdentifier: CellIdentifier] autorelease];
    }
    cell.textLabel.text = [dataArray objectAtIndex:indexPath.row];    return cell;
}

and from the code below am I doing the right thing to de-alloc the dataArray or should it be release or both.
Interface

@interface myViewController : UIViewController
{
    NSArray *dataArray;
}

@property(retain,nonatomic) NSArray *dataArray;
@end

From Implementation

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.dataArray=[[NSArray alloc] initWithObjects:@"XXX",@"YYY",@"ZZZ",nil];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    [self.dataArray dealloc];
}
  • 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-26T03:24:12+00:00Added an answer on May 26, 2026 at 3:24 am

    In your example, the cell you allocated will be autoreleased because you have sent the object the autorelease message. So you don’t need to worry about its memory being freed – that will happen automatically.

    As to your second question, in general, you should not call dealloc directly. The system calls dealloc for you when an object’s retain count goes to zero. You should read the following article which does a good job of explaining memory management in a very clear way: http://interfacelab.com/objective-c-memory-management-for-lazy-people/.

    The specific code you posted has two problems. First, based on what I said above, the dealloc should be replaced with a call to release. Second, you actually have a memory leak: when you alloc the dataArray object, it gets a retain count of 1. But you assign it to a property defined with the “retain” attribute. So the setter for that property will retain the object again, taking its retain count to 2. When you finally release, it will go back down to 1, but not to zero, so it won’t be released.

    To fix this, instead of assigning the alloc’d object to the property, assign it to the instance variable backing the property. By default, the instance variable will have the same name as the property, so you just do

    dataArray = [[NSArray alloc] initWithObjects:@"XXX",@"YYY",@"ZZZ",nil];
    

    If you explicitly gave the instance variable a name when you synthesized the property (by doing something like @synthesize dataArray = _dataArray, then use that name.

    Another option you have is to not alloc/init the array but rather to use the arrayWithObjects class method on NSArray. The object you get back from that will be autoreleased, so you don’t have to worry about managing it.

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

Sidebar

Related Questions

Can someone please help me figure out a way to achieve the following (see
Please see code below. The destructors are never called. Anyone know why and how
Having a bit of an issue please see the following code: window.onload = function
I have the following code for my google maps app. What I want to
Please see following methods. public static ProductsCollection GetDummyData(int? customerId, int? supplierId) { try {
Please see this piece of code: #include<stdio.h> #include<string.h> #include<stdlib.h> int main() { int i
Please see the code below: #include <iostream> #include <stdlib.h> #include <time.h> using namespace std;
I have an Adorner which adornes a Border (please see screenshot below). The MouseDown
Please consider the following: I am storing around 1.2 Million TIF files ranging from
I have the following html code <!DOCTYPE html> <html lang=en> <head> <meta name=viewport content=width=device-width;

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.