Hi guys,
i have a memory leak in my app. My app launches on a tableviewcontroller. i parse a json file to fill an array. Then this array is used to fill the tableview's cells. I fill my array with objects (class).
I do:
[tab_Demandes removeAllObjects];
for (NSDictionary *demandeD in demandes)
{
Demande *dem =[[Demande alloc] init];
dem.demTitle=title;
dem.demId=Id;
dem.demCreated=created;
[tab_Demandes addObject:dem];
[dem release];
}
My array and tableview are filled at launch, no problem. if i hit a table cell and then want to come back on the tableview my app crash on :
[tab_Demandes removeAllObjects];
If i dont do [dem release] i have leaks in instruments every time i reload tab_Demandes. RemoveAllObjects works but i have leaks.
Thx for any help as usual.
Wallou ++
Edit : here is where i made my cells. Maybe i mess up when creating the cells Actually tab_Demandes is declared in the delegate with get/set to access it from other classes (where i load my tableviewcontroller).
(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...
TabsAppDelegate *appDelegate = (TabsAppDelegate*)[[UIApplication sharedApplication] delegate];
cell.lbl_demId.text=[NSString stringWithFormat:@"%@", [[[appDelegate tab_Demandes] objectAtIndex:indexPath.row ] demId]];
cell.lbl_demCopro .text=[NSString stringWithFormat:@"%@", [[[appDelegate tab_Demandes] objectAtIndex:indexPath.row] demIdCopro ]];
cell.lbl_demImmeuble.text=[NSString stringWithFormat:@"%@", [[[appDelegate tab_Demandes] objectAtIndex:indexPath.row] demIdImmeuble]];
cell.lbl_demLot.text=[NSString stringWithFormat:@"%@", [[[appDelegate tab_Demandes] objectAtIndex:indexPath.row] demIdLot]];
cell.lbl_demDescriptif.text=[NSString stringWithFormat:@"%@", [[[appDelegate tab_Demandes] objectAtIndex:indexPath.row] demTitle]];
//NSLog(@"statut demande : %@",[[tab_Demandes objectAtIndex:indexPath.row] demStatut]);
if ([[[[appDelegate tab_Demandes] objectAtIndex:indexPath.row] demStatut] isEqualToString: @"Validée"])
{
cell.lbl_ImageView.image=[UIImage imageNamed:@"VDEM2.png"];
}
if([[[[appDelegate tab_Demandes] objectAtIndex:indexPath.row] demStatut] isEqualToString: @"Initiée"])
{
cell.lbl_ImageView.image=[UIImage imageNamed:@"IDEM.png"];
}
if([[[[appDelegate tab_Demandes] objectAtIndex:indexPath.row] demStatut] isEqualToString: @"Terminée"])
{
cell.lbl_ImageView.image=[UIImage imageNamed:@"TDEM.png"];
}
if([[[[appDelegate tab_Demandes] objectAtIndex:indexPath.row] demStatut] isEqualToString: @"En coursée"])
{
cell.lbl_ImageView.image=[UIImage imageNamed:@"EDEM.png"];
}
return cell;
}
NEW EDIT:
Demandes.h:
@interface Demande : NSObject {
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
Demandes.m:
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