gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 12:39:40 25 4
gpt4 key购买 nike

我正在尝试嵌入 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.

所以你知道我忘记了什么吗?

在此先感谢您的帮助;)

最佳答案

我复制了你的代码,并在设置了 -fsanitize=address 标志的 linux 环境中运行它,没有出现任何内存泄漏错误。

关于c++ - 带有示例的嵌入式 Google v8 内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54829503/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com