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

Protect native allocated typed array from being GC #1744

Merged
merged 3 commits into from May 23, 2019

Conversation

Projects
None yet
4 participants
@PatriceJiang
Copy link
Contributor

commented May 22, 2019

PatriceJiang added some commits May 22, 2019

@PatriceJiang

This comment has been minimized.

Copy link
Contributor Author

commented May 22, 2019

@minggo 麻烦有空review下

@@ -436,13 +436,15 @@ static bool js_CanvasRenderingContext2D_setCanvasBufferUpdatedCallback(se::State
se::ValueArray args;
args.resize(1);
ok &= Data_to_seval(larg0, &args[0]);
args[0].toObject()->root();

This comment has been minimized.

Copy link
@minggo

minggo May 22, 2019

Contributor

se::Value 的构造函数可以传入参数防止 GC

This comment has been minimized.

Copy link
@PatriceJiang

PatriceJiang May 22, 2019

Author Contributor

explicit Value(Object* o, bool autoRootUnroot = false);

explicit Value(const HandleObject& o, bool autoRootUnroot = false);

感觉这里显式调用比较合适

This comment has been minimized.

Copy link
@PatriceJiang

PatriceJiang May 22, 2019

Author Contributor

改成在Data_to_seval中处理

@@ -2509,7 +2509,7 @@ bool Data_to_seval(const cocos2d::Data& v, se::Value* ret)
else
{
se::HandleObject obj(se::Object::createTypedArray(se::Object::TypedArrayType::UINT8, v.getBytes(), v.getSize()));
ret->setObject(obj);
ret->setObject(obj, true);

This comment has been minimized.

Copy link
@minggo

minggo May 22, 2019

Contributor

HandleObject 应该已经处理了 root, unroot 了吧。

This comment has been minimized.

Copy link
@PatriceJiang

PatriceJiang May 22, 2019

Author Contributor

HandleObject在析构时进行了unroot, 过早了。 需要把typed array扩展到se::Value* ret的生命周期。

This comment has been minimized.

Copy link
@minggo

minggo May 22, 2019

Contributor

有两个疑问:

  1. 这个文件里的所有函数都有这个问题。
  2. 如果这样的话,那么就没必要创建 HandleObject 对象的吧。

This comment has been minimized.

Copy link
@PatriceJiang

PatriceJiang May 23, 2019

Author Contributor
  1. 是的
  2. HandleObject设计上可以 保护初始化过程中不被 GC
@minggo

This comment has been minimized.

Copy link
Contributor

commented May 23, 2019

GC 的问题先这么临时处理吧。等使用了 V8 有了 scope 后就不会有这个问题了。不过 JSC 也是很奇葩,新创建的内存照理应该是放在新生代,怎么这么快就被 GC 了。

@jareguo

This comment has been minimized.

Copy link
Contributor

commented May 23, 2019

这个问题也是这个地方引起的吗? https://forum.cocos.com/t/jsobjectref-root-unroot-gc/74369

@PatriceJiang

This comment has been minimized.

Copy link
Contributor Author

commented May 23, 2019

是的 @jareguo

@minggo

minggo approved these changes May 23, 2019

@jareguo jareguo changed the base branch from develop to v2.0.10-release May 23, 2019

@jareguo jareguo merged commit bba5ed2 into cocos-creator:v2.0.10-release May 23, 2019

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@jareguo

This comment has been minimized.

Copy link
Contributor

commented May 23, 2019

修复原生平台上 GC 可能导致崩溃的问题

@caochao

This comment has been minimized.

Copy link

commented May 27, 2019

赞一个

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.