improve editbox memory management

improve videoplayer memory management

improve webview memory management

add missing API doc annotation.

improve API docs

improve api docs

remove unneeded code

fix typo

refine API docs

remove unintened docs deletion
This commit is contained in:
zilongshanren
2017-06-01 14:42:44 +08:00
parent 889c3e8690
commit f07fecffd6
6 changed files with 61 additions and 19 deletions
+14
View File
@@ -626,3 +626,17 @@ cc.EditBox = module.exports = EditBox;
* @param {Event.EventCustom} event
* @param {EditBox} event.detail - The EditBox component.
*/
/**
* !#en if you don't need the EditBox and it isn't in any running Scene, you should
* call the destroy method on this component or the associated node explicitly.
* Otherwise, the created DOM element won't be removed from web page.
* !#zh
* 如果你不再使用 EditBox,并且组件未添加到场景中,那么你必须手动对组件或所在节点调用 destroy。
* 这样才能移除网页上的 DOM 节点,避免 Web 平台内存泄露。
* @example
* editbox.node.parent = null; // or editbox.node.removeFromParent(false);
* // when you don't need editbox anymore
* editbox.node.destroy();
* @method destroy
*/
+18 -1
View File
@@ -347,6 +347,8 @@ var VideoPlayer = cc.Class({
/**
* !#en Gets the duration of the video
* !#zh 获取视频文件的播放总时长
* @method getDuration
* @returns {Number}
*/
getDuration: function() {
if(this._sgNode) {
@@ -358,6 +360,8 @@ var VideoPlayer = cc.Class({
/**
* !#en Determine whether video is playing or not.
* !#zh 判断当前视频是否处于播放状态
* @method isPlaying
* @returns {Boolean}
*/
isPlaying: function() {
if(this._sgNode) {
@@ -365,7 +369,6 @@ var VideoPlayer = cc.Class({
}
return false;
}
});
cc.VideoPlayer = module.exports = VideoPlayer;
@@ -440,3 +443,17 @@ cc.VideoPlayer = module.exports = VideoPlayer;
* @param {Event.EventCustom} event
* @param {VideoPlayer} event.detail - The VideoPlayer component.
*/
/**
* !#en if you don't need the VideoPlayer and it isn't in any running Scene, you should
* call the destroy method on this component or the associated node explicitly.
* Otherwise, the created DOM element won't be removed from web page.
* !#zh
* 如果你不再使用 VideoPlayer,并且组件未添加到场景中,那么你必须手动对组件或所在节点调用 destroy。
* 这样才能移除网页上的 DOM 节点,避免 Web 平台内存泄露。
* @example
* videoplayer.node.parent = null; // or videoplayer.node.removeFromParent(false);
* // when you don't need videoplayer anymore
* videoplayer.node.destroy();
* @method destroy
*/
+14 -1
View File
@@ -152,7 +152,6 @@ var WebView = cc.Class({
cc.Component.EventHandler.emitEvents(this.webviewEvents, this, EventType.ERROR);
this.node.emit('error', this);
}
});
cc.WebView = module.exports = WebView;
@@ -185,3 +184,17 @@ cc.WebView = module.exports = WebView;
* @param {Event.EventCustom} event
* @param {WebView} event.detail - The WebView component.
*/
/**
* !#en if you don't need the WebView and it isn't in any running Scene, you should
* call the destroy method on this component or the associated node explicitly.
* Otherwise, the created DOM element won't be removed from web page.
* !#zh
* 如果你不再使用 WebView,并且组件未添加到场景中,那么你必须手动对组件或所在节点调用 destroy。
* 这样才能移除网页上的 DOM 节点,避免 Web 平台内存泄露。
* @example
* webview.node.parent = null; // or webview.node.removeFromParent(false);
* // when you don't need webview anymore
* webview.node.destroy();
* @method destroy
*/
+8 -14
View File
@@ -321,15 +321,9 @@ _ccsg.EditBox = _ccsg.Node.extend({
this._renderCmd.stayOnTop(this._alwaysOnTop);
},
onEnter: function () {
_ccsg.Node.prototype.onEnter.call(this);
//in case the EditBox being used after changing parent
this.createDomElementIfNeeded();
},
onExit: function () {
_ccsg.Node.prototype.onExit.call(this);
this._renderCmd._removeDomFromGameContainer();
cleanup: function () {
this._super();
this._renderCmd.removeDom();
},
_onTouchBegan: function (touch) {
@@ -675,7 +669,7 @@ _ccsg.EditBox.KeyboardReturnType = KeyboardReturnType;
proto._createDomInput = function () {
this._removeDomFromGameContainer();
this.removeDom();
var thisPointer = this;
var tmpEdTxt = this._edTxt = document.createElement('input');
@@ -770,7 +764,7 @@ _ccsg.EditBox.KeyboardReturnType = KeyboardReturnType;
};
proto._createDomTextArea = function () {
this._removeDomFromGameContainer();
this.removeDom();
var thisPointer = this;
var tmpEdTxt = this._edTxt = document.createElement('textarea');
@@ -980,7 +974,7 @@ _ccsg.EditBox.KeyboardReturnType = KeyboardReturnType;
}
if (cc.sys.isMobile && !this._editingMode) {
// Pre adaptation and
// Pre adaptation and
this._beginEditingOnMobile(this._editBox);
}
this._editingMode = true;
@@ -1177,7 +1171,7 @@ _ccsg.EditBox.KeyboardReturnType = KeyboardReturnType;
cc.game.container.appendChild(this._edTxt);
};
proto._removeDomFromGameContainer = function () {
proto.removeDom = function () {
var editBox = this._edTxt;
if(editBox){
var hasChild = Utils.contains(cc.game.container, editBox);
@@ -1197,7 +1191,7 @@ _ccsg.EditBox.KeyboardReturnType = KeyboardReturnType;
this._textLabel = null;
this._placeholderLabel = null;
this._editingMode = false;
this.__fullscreen = false;
this.__autoResize = false;
this.__rotateScreen = false;
+5 -1
View File
@@ -146,13 +146,17 @@ _ccsg.VideoPlayer = _ccsg.Node.extend(/** @lends _ccsg.VideoPlayer# */{
list.push(this);
},
cleanup: function () {
this._super();
this._renderCmd.removeDom();
},
onExit: function () {
_ccsg.Node.prototype.onExit.call(this);
var list = _ccsg.VideoPlayer.elements;
var index = list.indexOf(this);
if(index !== -1)
list.splice(index, 1);
this._renderCmd.removeDom();
},
setVisible: function ( visible ) {
+2 -2
View File
@@ -182,8 +182,8 @@ _ccsg.WebView = _ccsg.Node.extend(/** @lends _ccsg.WebView# */{
this._renderCmd.updateSize(width, height);
},
onExit: function () {
_ccsg.Node.prototype.onExit.call(this);
cleanup: function () {
this._super();
this._renderCmd.removeDom();
},