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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:52:09+00:00 2026-05-17T01:52:09+00:00

i have a leak issue in my app. I’m trying to add and remove

  • 0

i have a leak issue in my app.

I’m trying to add and remove objects to a NSMutableArray.

Here is the class Demande :

@interface Demande : NSObject { 
//attibuts de la classe demande
NSString *demId;
NSString *demStatut;
NSString *demTitle;
NSString *demCreated;
NSString *demIdCopro;
NSString *demIdImmeuble;
NSString *demIdLot;
NSString *demDescriptif;
NSString *demAuteur;
NSString *demIdAuteur;
NSString *demLoginAuteur;   
}
@property (retain,nonatomic) NSString *demId;
@property (retain,nonatomic) NSString *demIdCopro;
@property (retain,nonatomic) NSString *demIdImmeuble;    
@property (retain,nonatomic) NSString *demIdLot;
@property (retain,nonatomic) NSString *demDescriptif;
@property (retain,nonatomic) NSString *demStatut;
@property (retain,nonatomic) NSString *demTitle;
@property (retain,nonatomic) NSString *demCreated;
@property (retain,nonatomic) NSString *demAuteur;
@property (retain,nonatomic) NSString *demIdAuteur;
@property (retain,nonatomic) NSString *demLoginAuteur; 
@end


#import "Demande.h"
@implementation Demande

@synthesize demId,demIdCopro,demIdImmeuble,demIdLot,demDescriptif,demStatut,demTitle,demCreated,demAuteur,demIdAuteur,demLoginAuteur;

- (void)dealloc {   

[demId release];
[demIdCopro release];
[demId release];
[demIdImmeuble release];
[demIdLot release];
[demDescriptif release];
[demStatut release];
[demTitle release];
[demCreated release];
[demAuteur release];
[demIdAuteur release];
[demLoginAuteur release];    
[super dealloc];

}
@end

What i try to do in MyTableViewController :

@interface MyTableViewController : UITableViewController {

IBOutlet UITableView *tableV;
NSMutableArray *tab_Demandes;   
}
@end

@implementation MyTableViewController

- (void)requestDReloadDone:(ASIHTTPRequest *)request
{   

NSData *responseData = [request responseData];  

NSString *jsonString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
//NSLog(@"JSON: %@",jsonString);

NSDictionary *results = [jsonString JSONValue];

NSArray *demandes = [results objectForKey:@"Demandes"]; 

    [tab_Demandes removeAllObjects]; // -------- CRASH HERE !!!, except the first time through the method  because the array is empty  

    for (NSDictionary *demandeD in demandes)
{

    //parse du JSON
    NSString *titre = [demandeD objectForKey:@"Title"];
    NSString *desriptif = [demandeD objectForKey:@"Description"];
    NSString *Id = [demandeD objectForKey:@"Id"];
    NSString *created = [demandeD objectForKey:@"Created"];
    NSString *statut = [demandeD objectForKey:@"Statut"];
    NSString *copropriete = [demandeD objectForKey:@"Copropriete"];
    NSString *immeuble = [demandeD objectForKey:@"Immeuble"];
    NSString *lot = [demandeD objectForKey:@"Lot"];
    NSString *auteur = [demandeD objectForKey:@"Author"];
    NSString *auteurId = [demandeD objectForKey:@"IdAuthor"];
    NSString *auteurLogin = [demandeD objectForKey:@"Login"];

    //Creation de l'objet
    Demande *dem =[[Demande alloc] init];       
    dem.demTitle=titre;
    dem.demId=Id;
    dem.demCreated=created;

    NSString *descriptifDecode = [desriptif stringByReplacingPercentEscapesUsingEncoding:
                                  NSASCIIStringEncoding];       

    dem.demDescriptif=descriptifDecode;
    dem.demIdCopro=copropriete;
    dem.demIdImmeuble=immeuble;
    dem.demIdLot=lot;
    dem.demStatut=statut;
    dem.demAuteur=auteur;
    dem.demIdAuteur=auteurId;
    dem.demLoginAuteur=auteurLogin;

    [tab_Demandes addObject:dem];

    [dem release];
}

[tableV reloadData];

[jsonString release];
}

On the first launch of the app my array tab_Demandes is empty so everything is fine [removeAllObjects] works as there are no objects in it.
When i reload the tab_Demandes i need to clear it. That’s when the app crashes

I realised that if i do :

- (void)dealloc {   
     /*
[demId release];
[demIdCopro release];
[demId release];
[demIdImmeuble release];
[demIdLot release];
[demDescriptif release];
[demStatut release];
[demTitle release];
[demCreated release];
[demAuteur release];
[demIdAuteur release];
[demLoginAuteur release];
     */  
[super dealloc];
}

in the Demande class i then can do

[tab_Demandes removeAllObjects]

in TableViewController.

But then i have the properties as leaked for each object Demande. It’s like when i do [dem release] the properties are also rleased and when i want to do [removeAllObjects] from my tab_Demandes there are no properties to release and i get a Bad_Access.

If anyone has an idea …

EDIT: cellForROw method:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {    

static NSString *CellIdentifier = @"Cell";    
CustomCellViewController *cell = (CustomCellViewController *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) 
{
   // NSLog(@"Cell created");
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCellViewController" owner:nil options:nil];

    for(id currentObject in topLevelObjects)
    {
        if([currentObject isKindOfClass:[CustomCellViewController class]])
        {
            cell = (CustomCellViewController *)currentObject;
            break;
        }
    }
}

    // Set up the cell...   

    cell.lbl_demId.text=[NSString stringWithFormat:@"%@", [[tab_Demandes objectAtIndex:indexPath.row ] demId]]; 
    cell.lbl_demCopro .text=[NSString stringWithFormat:@"%@", [[tab_Demandes objectAtIndex:indexPath.row] demIdCopro ]];
    cell.lbl_demImmeuble.text=[NSString stringWithFormat:@"%@", [[tab_Demandes objectAtIndex:indexPath.row] demIdImmeuble]];
    cell.lbl_demLot.text=[NSString stringWithFormat:@"%@", [[tab_Demandes objectAtIndex:indexPath.row] demIdLot]];
    cell.lbl_demDescriptif.text=[NSString stringWithFormat:@"%@", [[tab_Demandes objectAtIndex:indexPath.row] demTitle]];
    if ([[[tab_Demandes objectAtIndex:indexPath.row] demStatut] isEqualToString: @"Validée"])
    {
    cell.lbl_ImageView.image=[UIImage imageNamed:@"VDEM2.png"];
    }
    if([[[tab_Demandes objectAtIndex:indexPath.row] demStatut] isEqualToString: @"Initiée"])
    {
       cell.lbl_ImageView.image=[UIImage imageNamed:@"IDEM.png"];
    }
    if([[[tab_Demandes objectAtIndex:indexPath.row] demStatut] isEqualToString: @"Terminée"])
    {
    cell.lbl_ImageView.image=[UIImage imageNamed:@"TDEM.png"];
    }
    if([[[tab_Demandes objectAtIndex:indexPath.row] demStatut] isEqualToString: @"En coursée"])
    {
    cell.lbl_ImageView.image=[UIImage imageNamed:@"EDEM.png"];

    }

return cell;       
} 
  • 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-17T01:52:09+00:00Added an answer on May 17, 2026 at 1:52 am

    Where it tab_Demandes being intialized?

    It’s not enough to only declare it in the .h file, you must also tell the compiler to alloc and init it.

    A simple fix might be replacing the line [tab_Demandes removeAllObjects]; with

    if(!tab_Demandes) { // tab_Demandes is nil and has not previously been created
        tab_Demandes = [[NSMutableArray arrayWithCapacity:10] retain];
    } else {
        [tab_Demandes removeAllObjects];
    }
    

    Don’t forget to [tab_Demandes release] in your dealloc method

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

Sidebar

Related Questions

I am facing memory leak issue with very simple code.I have class 'TestClass' @interface
I have an .net app that seems to have a memory leak issue(s). The
I have found a similar issue: NSMutableArray addObject in for loop - memory leak
I have an issue with a memory leak. I have a base-class pointer. From
I have a memory leak in my iOS app which sometimes causes it to
I have a static std::vector in a class. When I use Microsoft's memory leak
I have a bit of a memory leak issue in my Flex application, and
I have a memory leak issue in my application which loads a large amount
I've been having this memory leak issue for days and I think I have
I have created a class to download images from web. Issue is there is

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.