0

pushViewController を使用すると問題が発生します - メモリは 9 MB から 28 MB になりますが、popViewController を使用してもメモリは解放されません (9 MB になるはずです) が、28 MB を取得しています。

以下は、ビューをプッシュするコードです。

/* Video Handler */
-(void)showVideo:(id)sender {
    UIButton *btn               = (UIButton *)sender;
    int nid                         =   btn.tag;

    masterdb *mdbT          = [[masterdb alloc] init];
    izc_news *nclsT         =   [mdbT getNewsDetail:nid];
    [mdbT release];
    NSString *vlink         =   nclsT.VideoLink;

    PlayVideo *vd               =   [[PlayVideo alloc] init];
    vd.hidesBottomBarWhenPushed =   YES;
    vd.videoLink                =   vlink;

    [self.navigationController pushViewController:vd animated:YES];
    [vd release];
    vd                                  =   nil;
}

以下はPlayVideo.hファイルです

#import <MediaPlayer/MediaPlayer.h>

@interface PlayVideo : UIViewController {
    NSString *videoLink;
    MPMoviePlayerController *mp;
    UIActivityIndicatorView *spinner;
}

@property(nonatomic, retain) NSString *videoLink;
@property(nonatomic, retain) MPMoviePlayerController *mp;
@property(nonatomic, retain) UIActivityIndicatorView *spinner;

@end

最後に、以下は PlayVideo.m ファイルです

#import "PlayVideo.h"


@implementation PlayVideo

@synthesize videoLink; 
@synthesize mp;
@synthesize spinner;


- (void) viewDidLoad {

    [super viewDidLoad];

    videoLink       =   @"http://www.izooconnect.com/fwzNew/vids/testVid.mov";

    [[UIApplication sharedApplication] setStatusBarHidden:YES];

    [[self view] setBounds:CGRectMake(0, 0, 480, 320)];
    [[self view] setCenter:CGPointMake(160, 240)];
    [[self view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)]; 


    CGRect mainBounds               = [[UIScreen mainScreen] bounds];
    CGRect indicatorBounds  = CGRectMake(mainBounds.size.height / 2 - 24, mainBounds.size.width / 2 - 24, 48, 48);
    spinner                                 =          [[UIActivityIndicatorView alloc] initWithFrame:indicatorBounds];
    spinner.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
    spinner.tag                         =   1;
    [spinner startAnimating];
    [self.view addSubview:spinner];


    mp =  [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString: videoLink]];


    [[NSNotificationCenter defaultCenter] addObserver:self 
                                                                                 selector:@selector(moviePreloadDidFinish:) 
                                                                                         name:MPMoviePlayerContentPreloadDidFinishNotification 
                                                                                     object:nil];


    [[NSNotificationCenter defaultCenter] addObserver:self 
                                                                                 selector:@selector(moviePlayBackDidFinish:) 
                                                                                         name:MPMoviePlayerPlaybackDidFinishNotification 
                                                                                     object:nil];


[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];

    [[mp view] setFrame:CGRectMake(0, 0, 480, 320)];

    [mp setControlStyle:MPMovieControlStyleFullscreen];
    [mp setFullscreen:YES];

    [self.view addSubview:mp.view];

}


- (void) moviePreloadDidFinish: (NSNotification *) notification {
    UIActivityIndicatorView *tmpimg = (UIActivityIndicatorView *)[self.view viewWithTag:1];
    [tmpimg removeFromSuperview];
    [mp play];
}


- (void) moviePlayBackDidFinish: (NSNotification *) notification {
    [self.navigationController popViewControllerAnimated:YES];
}




- (void) dealloc {
    [mp release];
    [spinner release];
    [super dealloc];
}

@end

問題を特定しようとしましたが、何も見つかりませんでした。

4

2 に答える 2

1

あなたの問題はここにあります

- (void) moviePlayBackDidFinish: (NSNotification *) notification {
    mp  =   nil;
    [self.navigationController popViewControllerAnimated:YES];
}

解放せずに mp = nil を設定しており、dealloc で解放すると、mp の実際のインスタンスではなく、nil にメッセージが送信されます。

mp を解放してから nil に設定します。

于 2011-11-19T09:27:25.523 に答える
0

ビューコントローラーによって保持されている参照のいずれかがまだメモリ内にある場合、dealloc メソッドは呼び出されません。したがって、ビュー コントローラーをポップアップする前に mp オブジェクトを解放する必要があります。詳細については、この投稿を参照してください。iPhone - ビュー コントローラーの dealloc はいつ呼び出されますか?

于 2011-11-19T12:40:18.363 に答える