无法从 NSMutableArray 中删除对象
我正在尝试从 NSMutableArray 中删除对象,但我不断收到 bad_access 错误。
我使用了“removeAllObjects”和“removeObjectAtIndex”,但这些都不起作用。
如果我将对象添加到这个数组中,一切都很好。
我想做的是在再次填充之前清除数组。
在尝试填充之前我没有释放数组。
感谢您的帮助。
再见
代码:
[tab_Demandes removeAllObjects];
for (NSDictionary *demandeD in demandes)
{
NSInteger i=0;
NSString *title = [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"];
Demande *dem =[[Demande alloc] init];
dem.demTitle=title;
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 replaceObjectAtIndex:i withObject:dem];
//i=i+1;
[tab_Demandes addObject:dem];
//[dem release];
}
如果稍后需要删除添加到选项卡的对象,我什么时候需要释放它们?因为内存泄漏。
i am trying to remove objects from my NSMutableArray but i keep getting bad_access error.
I used "removeAllObjects" and "removeObjectAtIndex" but none of these work.
If i add objects to this array , everything is fine.
What i want to do is to clear my array before filling it again.
I didnt release the array before trying to fill.
Thx for the help.
Bye
code:
[tab_Demandes removeAllObjects];
for (NSDictionary *demandeD in demandes)
{
NSInteger i=0;
NSString *title = [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"];
Demande *dem =[[Demande alloc] init];
dem.demTitle=title;
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 replaceObjectAtIndex:i withObject:dem];
//i=i+1;
[tab_Demandes addObject:dem];
//[dem release];
}
When do i need to release the objects i add to the tab if i need to remove them later? because of memory leaks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
并不是您释放了数组,而是数组中的一个(或多个)对象已经在数组外部释放了。尝试打开 NSZombieEnabled 看看是否可以找出是哪一个。
It's not that you released the array, it's that one (or more) of the objects in the array was already released outside of the array. Try turning on NSZombieEnabled to see if you can figure out which one.