带有示例的嵌入式Google v8内存泄漏

时间:2019-02-22 14:41:31

标签: c++ memory-leaks visual-studio-2017 v8 embedded-v8

我正在尝试嵌入V8,但内存泄漏。以下最少的代码重现了泄漏。

int main(int argc, char* argv[])
{
    // V8 version 7.1.302.33
    v8::V8::InitializeICUDefaultLocation(argv[0]);
    v8::V8::InitializeExternalStartupData(argv[0]);
    std::unique_ptr<v8::Platform> platform = v8::platform::NewDefaultPlatform();
    v8::V8::InitializePlatform(platform.get());
    v8::V8::Initialize();

    v8::Isolate::CreateParams create_params;
    create_params.array_buffer_allocator = v8::ArrayBuffer::Allocator::NewDefaultAllocator();

    v8::Isolate* pIsolate = v8::Isolate::New(create_params); // If I remove this line and the next one, memory leak disappears
    pIsolate->Dispose();

    v8::V8::Dispose();
    v8::V8::ShutdownPlatform();
    delete create_params.array_buffer_allocator;
}

使用此代码,我的visual studio 2017在输出中打印这些泄漏

Detected memory leaks!
    Dumping objects ->
{5565} normal block at 0x000001BA6F417950, 8 bytes long.
    Data: < i    > 00 00 E8 69 18 00 00 00
{5564} normal block at 0x000001BA6F416960, 16 bytes long.
    Data : <8 >o > 38 D7 3E 6F BA 01 00 00 00 00 00 00 00 00 00 00
{5563} normal block at 0x000001BA6F3ED720, 56 bytes long.
    Data: <  >o > o > A0 D6 3E 6F BA 01 00 00 A0 D6 3E 6F BA 01 00 00
{989} normal block at 0x000001BA6F4194E0, 128 bytes long.
    Data: <  >o > o > A0 D6 3E 6F BA 01 00 00 A0 D6 3E 6F BA 01 00 00
{988} normal block at 0x000001BA6F416CD0, 16 bytes long.
    Data: < p `             > 70 B4 60 0A FF 7F 00 00 00 00 00 00 00 00 00 00
{987} normal block at 0x000001BA6F417270, 16 bytes long.
    Data : < X `             > 58 B4 60 0A FF 7F 00 00 00 00 00 00 00 00 00 00
{986} normal block at 0x000001BA6F3ED6A0, 56 bytes long.
    Data : <  >o > o > 20 D7 3E 6F BA 01 00 00 20 D7 3E 6F BA 01 00 00
    Object dump complete.

那么你知道我忘记了什么吗?

在此先感谢您的帮助;)

1 个答案:

答案 0 :(得分:0)

我复制了您的代码,并在Linux环境下运行了-fsanitize = address标志,未收到任何内存泄漏错误。