0

为什么将 nil 分配给 nsmutabledictioanry 并分配会导致崩溃并在此时显示内存释放?

    self.delegate.replenishAddedmaterials = nil;
    self.delegate.replenishAddedmaterials = [[NSMutableDictionary alloc] init];
    MATERIAL_ITEM *materialItem = [[MATERIAL_ITEM alloc] init];
    VENDOR_HEADER *vendor = [[VENDOR_HEADER alloc] init];
    PURCHASING_ORG_HEADER *purOrg = [[PURCHASING_ORG_HEADER alloc] init];

    [self.delegate.replenishAddedmaterials setObject:[NSMutableArray arrayWithObject:materialItem] forKey:materialItem];
    [[self.delegate.replenishAddedmaterials objectForKey:materialItem] addObject:vendor];
    [[self.delegate.replenishAddedmaterials objectForKey:materialItem] addObject:purOrg];

执行 nsmutabledictionary 分配后,我收到以下消息

* -[MATERIAL_ITEM release]: message sent to deallocated instance 0x11e62810>我已经在 ARC 中实现了我的项目

4

1 回答 1

1

你确定这条线是正确的吗?

     [self.delegate.replenishAddedmaterials setObject:[NSMutableArray 
arrayWithObject:materialItem] forKey:materialItem];

您使用数组上的对象作为键,这真的很奇怪。

尝试自己创建密钥:

     [self.delegate.replenishAddedmaterials setObject:[NSMutableArray 
arrayWithObject:materialItem] forKey:@"materialItemKey"];
于 2013-11-05T10:02:51.323 回答