-1

资源创建者:

(void)parseNodeAsMap:(XMPPElement*)message
{
 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

if ([[message name] isEqualToString:@"presence"]) {
   // NSLog(@"presence--%@--%@",[message attributeStringValueForName:@"type"],[message from].resource);
    if ([[message attributeStringValueForName:@"type"] isEqualToString:@"unavailable"]) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"VedioChatUserStatusNoti" object:[message from].resource userInfo:[NSDictionary dictionaryWithObject:@"0" forKey:@"key"]];
    }else {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"VedioChatUserStatusNoti" object:[message from].resource userInfo:nil];
    }

}else if([[message name] isEqualToString:@"message"]) {

    if ([[message elementForName:@"body"] stringValue].length<1) {

        [[NSNotificationCenter defaultCenter] postNotificationName:@"VedioChatMsgNoti" object:@"...." userInfo:nil];
    }else {
     //   NSLog(@"message--%@",[[message elementForName:@"body"] stringValue]);
        [[NSNotificationCenter defaultCenter] postNotificationName:@"VedioChatMsgNoti" object:[[message elementForName:@"body"] stringValue] userInfo:nil];
    }

}else {

}
message = nil;
[pool drain];
}

并在此使用:`#pragma mark NOTI

(void)getChatUserStatus:(NSNotification*)noti{

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSArray *user = [[noti object]componentsSeparatedByString:@"@userid"];
if (user.count<2)
{
    RoomUser _ru = {_ru.p_id = userId,_ru.nickName = [[user objectAtIndex:0] copy],_ru.role = @"0"};
    [_listDic setObject:[NSValue valueWithBytes:&_ru objCType:@encode(RoomUser)] forKey:userId];

    int insertIndex = 0;
    ...
    [_listKeys insertObject:userId atIndex:insertIndex];


    onlineUserNum++;
}else {
    RoomUser _ru = {_ru.p_id = [[user objectAtIndex:1] copy],_ru.nickName = [[user objectAtIndex:0] copy],_ru.role = [[user objectAtIndex:2] copy]};

    if (![noti userInfo]) {
        [_listDic setObject:[NSValue valueWithBytes:&_ru objCType:@encode(RoomUser)] forKey:[user objectAtIndex:1]];

        int insertIndex = 0;
        ...
        [_listKeys insertObject:_ru.p_id atIndex:insertIndex];

        onlineUserNum++;

    }else {

        [_listKeys removeObject:_ru.p_id];
        [_listDic removeObjectForKey:_ru.p_id];
        onlineUserNum--;
    }
}

//设置第一个标题的 内容
[(UIButton*)[titlesView viewWithTag:1] setTitle:[NSString stringWithFormat:@"%@ %d",[_titles objectAtIndex:0],onlineUserNum] forState:UIControlStateNormal];
user = nil;
[pool drain];     

}
4

1 回答 1

1

您正在泄漏NSString对象,componentsSeparatedByString:因为您复制了它们:[[user objectAtIndex:0] copy].

当从字典中删除盒装的 RoomUser 时,您必须确保NSString正确释放实例。

更好的方法是不要携带 C 结构RoomUser,而是将数据放在字典或适当的 Objective-C 对象中。

于 2012-09-24T10:31:33.867 回答