Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GC problem #2797

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: node ./scripts/ci-release.js "${{ github.event.head_commit.message }}"
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
run: node ./scripts/ci-release.js
- run: git status
- run: git log
1 change: 1 addition & 0 deletions packages/core/weapp/class/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default class Base {
constructor() {
this._events = {};
this._watchers = [];
this.$children = [];
}

$set(target, key, val) {
Expand Down
29 changes: 29 additions & 0 deletions packages/core/weapp/class/WepyComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ import Watcher from '../observer/watcher';
import { isArr, isPlainObject } from '../../shared/index';

import { renderNextTick } from '../util/next-tick';
import Dirty from './Dirty';

export default class WepyComponent extends Base {

constructor() {
super();
this.$children = [];
this.$dirty = new Dirty('path');
this.$refs = {};
}
$watch(expOrFn, cb, options) {
let vm = this;
if (isArr(cb)) {
Expand Down Expand Up @@ -52,6 +60,27 @@ export default class WepyComponent extends Base {
$trigger(event, data, option) {
this.$wx.triggerEvent(event, { arguments: [data] }, option);
}

$destroy() {
this.$children.forEach(child => {
if (!child._detached) {
child.$destroy();
}
});
Comment on lines +65 to +69
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个是不是没必要,组件自己也是会调用 detached 进行析构的

this._watcher.cleanupDeps();
this._watcher.teardown();
this._watchers.forEach(item => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this._watchers.slice().forEach,因为 teardown 会从 _watchers 里把自身删掉

item.cleanupDeps();
item.teardown();
});
this._watchers = [];
this._events = {};
this._detached = true;
delete this._data.__ob__;
delete this._data;
delete this._watcher;
Comment on lines +79 to +81
Copy link
Collaborator

Choose a reason for hiding this comment

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

这几个应该都不用删。测了下,删这几个
delete this.$parent; delete this.$root; delete this.$wx.$wepy;

delete this.$root;
}
}

WepyComponent.prototype.$nextTick = renderNextTick;
20 changes: 10 additions & 10 deletions packages/core/weapp/init/lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { initData } from './data';
import { initComputed } from './computed';
import { initMethods } from './methods';
import { isArr, isFunc } from '../../shared/index';
import Dirty from '../class/Dirty';
import {
WEAPP_APP_LIFECYCLE,
WEAPP_PAGE_LIFECYCLE,
Expand All @@ -36,7 +35,7 @@ const callUserMethod = function(vm, userOpt, method, args) {
return result;
};

const getLifecycycle = (defaultLifecycle, rel, type) => {
const getLifecycle = (defaultLifecycle, rel, type) => {
let lifecycle = defaultLifecycle.concat([]);
if (rel && rel.lifecycle && rel.lifecycle[type]) {
let userDefinedLifecycle = [];
Expand Down Expand Up @@ -75,7 +74,7 @@ export function patchAppLifecycle(appConfig, options, rel = {}) {
return callUserMethod(vm, vm.$options, 'onLaunch', args);
};

let lifecycle = getLifecycycle(WEAPP_APP_LIFECYCLE, rel, 'app');
let lifecycle = getLifecycle(WEAPP_APP_LIFECYCLE, rel, 'app');

lifecycle.forEach(k => {
// it's not defined aready && user defined it && it's an array or function
Expand All @@ -92,10 +91,6 @@ export function patchLifecycle(output, options, rel, isComponent) {
const initLifecycle = function(...args) {
let vm = new initClass();

vm.$dirty = new Dirty('path');
vm.$children = [];
vm.$refs = {};

this.$wepy = vm;
vm.$wx = this;
vm.$is = this.is;
Expand Down Expand Up @@ -165,7 +160,7 @@ export function patchLifecycle(output, options, rel, isComponent) {

// 增加组件页面声明周期
output.pageLifetimes = {};
const lifecycle = getLifecycycle(WEAPP_COMPONENT_PAGE_LIFECYCLE, rel, 'component');
const lifecycle = getLifecycle(WEAPP_COMPONENT_PAGE_LIFECYCLE, rel, 'component');

lifecycle.forEach(function(k) {
if (!output.pageLifetimes[k] && options[k] && (isFunc(options[k]) || isArr(options[k]))) {
Expand Down Expand Up @@ -245,7 +240,7 @@ export function patchLifecycle(output, options, rel, isComponent) {
// }
// })

let lifecycle = getLifecycycle(WEAPP_PAGE_LIFECYCLE, rel, 'page');
let lifecycle = getLifecycle(WEAPP_PAGE_LIFECYCLE, rel, 'page');

lifecycle.forEach(k => {
if (!output[k] && options[k] && (isFunc(options[k]) || isArr(options[k]))) {
Expand All @@ -255,7 +250,12 @@ export function patchLifecycle(output, options, rel, isComponent) {
}
});
}
let lifecycle = getLifecycycle(WEAPP_COMPONENT_LIFECYCLE, rel, 'component');
output.detached = function(...args) {
let vm = this.$wepy;
vm.$destroy();
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个应该在 callUserMethod(vm, vm.$options, 'detached', args); 之后执行吧

return callUserMethod(vm, vm.$options, 'detached', args);
}
let lifecycle = getLifecycle(WEAPP_COMPONENT_LIFECYCLE, rel, 'component');

lifecycle.forEach(k => {
// beforeCreate is not a real lifecycle
Expand Down
9 changes: 7 additions & 2 deletions scripts/ci-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ function release(version, tag) {
.catch(e => console.log(e));
}

const { version, tag } = parseMsg(process.argv[2]);
const commitMsg = process.env.COMMIT_MESSAGE;

if (commitMsg) {
const { version, tag } = parseMsg(commitMsg);

release(version, tag);
}

release(version, tag);