Skip to content

Commit

Permalink
fix memory leak (#20110)
Browse files Browse the repository at this point in the history
  • Loading branch information
minggo committed Sep 17, 2019
1 parent 4c48060 commit e73b7f1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cocos/ui/UIVideoPlayer-ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ @implementation UIVideoViewWrapperIos
-(id)init:(void*)videoPlayer
{
if (self = [super init]) {
self.playerController = [AVPlayerViewController new];
self.playerController = [[AVPlayerViewController new] autorelease];

[self setRepeatEnabled:FALSE];
[self showPlaybackControls:TRUE];
Expand Down
2 changes: 1 addition & 1 deletion cocos/ui/UIWebViewImpl-ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ - (void)dealloc {

- (void)setupWebView {
if (!self.wkWebView) {
self.wkWebView = [[WKWebView alloc] init];
self.wkWebView = [[[WKWebView alloc] init] autorelease];
self.wkWebView.UIDelegate = self;
self.wkWebView.navigationDelegate = self;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ bool VideoPlayerTest::init()

_visibleRect = Director::getInstance()->getOpenGLView()->getVisibleRect();

// Should create video first to make sure video is destryed first. If not, then may crash.
// Because when destroying video, it will stop video which may trigger stopped event listener.
createVideo();

MenuItemFont::setFontSize(16);

auto fullSwitch = MenuItemFont::create("FullScreenSwitch", CC_CALLBACK_1(VideoPlayerTest::menuFullScreenCallback, this));
Expand Down Expand Up @@ -95,8 +99,6 @@ bool VideoPlayerTest::init()
_loopStatusLabel->setAnchorPoint(Vec2::ANCHOR_MIDDLE_RIGHT);
_loopStatusLabel->setPosition(Vec2(_visibleRect.origin.x + _visibleRect.size.width - 10,_visibleRect.origin.y + 185));
_uiLayer->addChild(_loopStatusLabel);

createVideo();

return true;
}
Expand Down

3 comments on commit e73b7f1

@Yongrui
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.wkWebView = [[[WKWebView alloc] init] autorelease];
改成这行之后退后台回来操作貌似会crash,应该是dealloc那里释放多了一次

@minggo
Copy link
Contributor Author

@minggo minggo commented on e73b7f1 Oct 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The property is declared as @property(nonatomic, retain) WKWebView *wkWebView;, so it will retain it. And if it will cause crash error, then it will not only crash after return from background. I will have a try.

And please use English in future.

@minggo
Copy link
Contributor Author

@minggo minggo commented on e73b7f1 Oct 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Yongrui i tested URL Open Test in cpp-tests, no crash happened. Could you please describe how to reproduce it in detail?

Please sign in to comment.