无法从 NSMutableArray 中删除对象

发布于 2024-09-24 01:38:31 字数 1729 浏览 2 评论 0原文

我正在尝试从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〆凄凉。 2024-10-01 01:38:31

并不是您释放了数组,而是数组中的一个(或多个)对象已经在数组外部释放了。尝试打开 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文