gpt4 book ai didi

objective-c - 奇怪的内存管理事件iOS

转载 作者:行者123 更新时间:2023-12-01 17:21:39 25 4
gpt4 key购买 nike

由于下面的代码中的某些原因,replies数组是正确的NSLogging描述,但是comment.replies数组是NSLogging空。

我立即认为这是由于代码中的内存管理问题引起的,但我不认为那是真的。

请您告诉我为什么会这样吗?

- (TBComment *) dictionaryToComment:(NSDictionary *)dict {
TBComment *comment = [[TBComment alloc] init];
[comment setBody:[dict objectForKey:@"body"]];
[comment setCommentID:[dict objectForKey:@"id"]];
[comment setCreated_at:[dict objectForKey:@"created_at"]];
[comment setUpdated_at:[dict objectForKey:@"updated_at"]];
[comment setUser:[self dictionaryToUser:[dict objectForKey:@"user"]]];
NSMutableArray *replies = nil;
if ([[dict allKeys] containsObject:@"replies"]) {
replies = [[NSMutableArray alloc] init];
for (NSDictionary *reply in [dict objectForKey:@"replies"]) {
NSLog(@"in");
[replies addObject:[self dictionaryToComment:reply]];
}
}
if (replies != nil) {
[comment setReplies:replies];
NSLog(@"COMMENT REPLIES = %@", comment.replies);
NSLog(@"REPLIES = %@", replies);
[replies release];
}
return [comment autorelease];
}

控制台->
2011-11-30 21:25:14.980 Timbrr[2379:f803] in
2011-11-30 21:25:14.980 Timbrr[2379:f803] COMMENT REPLIES = (null)
2011-11-30 21:25:14.980 Timbrr[2379:f803] REPLIES = (
"<TBComment: 0x68dbeb0>"
)


- (void) setReplies:(NSArray *)_replies {
hasReplies = (_replies == nil ? NO : ([_replies count] == 0 ? NO : YES));
//replies is synthesised
}

最佳答案

我会怀疑commentnil(尽管这需要nil中的显式TBComment -returning代码,这是可能的,但不常见),或者-replies-setReplies:的实现不正确。您是否有针对这些的自定义实现?

您的setReplies:实现永远不会设置_replies

关于objective-c - 奇怪的内存管理事件iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8333177/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com