2

VC を閉じると、メモリからすべてを解放していないことに気付きました。保持サイクルを見つける方法について、私は非常に迷っています。私は NSTimer と NSNotificationCenter を使用していますが、終了する前に Observers を無効にして削除し、弱いデリゲートを使用していることを確認しました。

リテンション サイクルは他にどこで発生している可能性がありますか? アニメブロックで?このような?

 [UIView animateWithDuration:.1 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                self.setListTableViewVertConst.constant = 0;
                self.setListTableViewHeightConst.constant = 264;
            } completion:^(BOOL finished) {

            }];

GCD を使用するときは、weakSelf を必ず使用します。

__weak typeof(self) weakSelf = self;
            dispatch_async(dispatch_get_main_queue(), ^{
                [weakSelf.remotePasswordTextField resignFirstResponder];
            });

助けてくれてありがとう。

編集:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    //Send the room code to be displayed on the respective view controllers. 
    if ([segue.identifier isEqualToString:@"toSetListRoomVC"]) {
        SetListRoomViewController *setListVC = segue.destinationViewController;
        setListVC.roomCode = self.roomCodeTextField.text;
    }

}

ビューウィルアピア

[super viewWillAppear:YES];


    self.socket = [[SocketKeeperSingleton sharedInstance]socket];
    self.socketID = [[SocketKeeperSingleton sharedInstance]socketID];

    NSString *roomCodeAsHost = [[SocketKeeperSingleton sharedInstance]hostRoomCode];
    /////////HOST/////////
    if ([[SocketKeeperSingleton sharedInstance]isHost]) {

        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(receiveHostSongAddedNotification:)
                                                     name:kQueueAdd
                                                   object:nil];

        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(receiveUserJoinedNotification:)
                                                     name:kUserJoined
                                                   object:nil];

        NSLog(@"User is the host of this room");
        self.isHost = YES;
        [self viewForNoCurrentArtistAsHost];
        self.roomCodeLabel.text = roomCodeAsHost;

        if (!self.hostQueue) {
            self.hostQueue = [[NSMutableArray alloc]init];
        }
        if (!self.hostCurrentArtist) {
            self.hostCurrentArtist = [[NSMutableDictionary alloc]init];
        }

        if (!self.player) {
            self.player = [[AVPlayer alloc]init];
        }
        if (!self.timer) {
            self.timer = [[NSTimer alloc]init];
        }
    }

    ///////NOT HOST///////
    else {
        // Add a notifcation observer and postNotification name for updating the tracks.
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(receiveQueueUpdatedNotification:)
                                                     name:kQueueUpdated
                                                   object:nil];

        //Add a notifcation observer and postNotification name for updating current artist.
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(receiveCurrentArtistUpdateNotification:)
                                                     name:kCurrentArtistUpdate
                                                   object:nil];

        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(receiveOnDisconnectNotification:)
                                                     name:kOnDisconnect
                                                   object:nil];

        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(receiveHostDisconnectNotification:)
                                                     name:kHostDisconnect
                                                   object:nil];


        //Add some animations upon load up. Purple glow and tableview animation.
        double delay = .4;
        [self purpleGlowAnimationFromBottomWithDelay:&delay];
        [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationBottom];

        //Set Current artist, if there is one.
        NSDictionary *currentArtist = [[SocketKeeperSingleton sharedInstance]currentArtist];
        [self setCurrentArtistFromCurrentArtist:currentArtist];


        //Set the current tracks, if there is one.
        NSArray *setListTracks = [[SocketKeeperSingleton sharedInstance]setListTracks];
        if (setListTracks) {
            self.tracks = setListTracks;
        }
    }
}

tableVIEW

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView.tag == 1) {
        if (self.isHost) {
            return [self.hostQueue count];
        }
        else return [self.tracks count];
    }
    else return [self.searchTracks count];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
4

2 に答える 2

0

このコードサンプルでは、__weak​​ forを使用していませんself

 [UIView animateWithDuration:.1 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                self.setListTableViewVertConst.constant = 0;
                self.setListTableViewHeightConst.constant = 264;
            } completion:^(BOOL finished) {

            }];

しかし、これは一見リテインサイクルを作っているようには見えません。あなたが投稿したコードには何もないようですので、おそらく別の場所にあります。保持サイクルがありますか?

とにかく、アプリを計測してみてください。それは役立つかもしれません。

于 2015-02-02T03:43:14.393 に答える