-1

リソース作成BY:

(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]

NSStringボックス化されたRoomUserがディクショナリから削除されたときに、インスタンスが適切に解放されることを確認する必要があります。

より良いアプローチは、C構造体を持ち歩くのではRoomUserなく、代わりにデータを辞書または適切なObjective-Cオブジェクトに配置することです。

于 2012-09-24T10:31:33.867 に答える