Sample(process.cc) add code crash

55 views
Skip to first unread message

滚开

unread,
Mar 6, 2019, 10:45:00 AM3/6/19
to v8-users


i just add:
```
isolate->Dispose();
v8::V8::Dispose();
v8::V8::ShutdownPlatform();
delete create_params.array_buffer_allocator;
```

i want Dispose the isolate and tear down V8.

Not allowed here? why?

Ben Noordhuis

unread,
Mar 7, 2019, 5:03:29 AM3/7/19
to v8-users
https://github.com/v8/v8/blob/4d39e3427824fafa35a6bfcdb23b05cd9c2db67d/samples/process.cc#L717
- the isolate is still entered (i.e., active) at that point.

helloev

unread,
Mar 7, 2019, 8:39:31 AM3/7/19
to v8-users

So here we don't need to release resources? If need to release it, what should we do?

I saw the scope here:

I tried to do it like this and still failed. 

Ben Noordhuis

unread,
Mar 7, 2019, 1:46:26 PM3/7/19
to v8-users
On Thu, Mar 7, 2019 at 2:39 PM helloev <stonedre...@gmail.com> wrote:
> So here we don't need to release resources? If need to release it, what should we do?

The process is terminating so any resources will be reclaimed anyway
but if you want to reclaim them manually, use proper scoping:

int main() {
// ...
{
Isolate::Scope isolate_scope(isolate);
// ...
} // closes the isolate scope
isolate->Dispose();
// ...
}

helloev

unread,
Mar 7, 2019, 11:13:46 PM3/7/19
to v8-users
int main(int argc , char* argv[]) {


 map
<string , string> options;
 
string file;
 
ParseOptions(argc , argv , &options , &file);
 
if (file.empty()) {
 fprintf
(stderr , "No script was specified.\n");
 
return 1;
 
}


 
// 初始化v8
 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();






 
Isolate::CreateParams create_params;
 create_params
.array_buffer_allocator = v8::ArrayBuffer::Allocator::NewDefaultAllocator();
 
Isolate* isolate = Isolate::New(create_params);
 gisolate
= isolate;


 
{
 
Isolate::Scope isolate_scope(isolate);
 
HandleScope scope(isolate);


 
Local<String> source;
 
if (!ReadFile(isolate , file).ToLocal(&source)) {
 fprintf
(stderr , "Error reading '%s'.\n" , file.c_str());
 
return 1;
 
}
 
JsHttpRequestProcessor processor(isolate , source);
 map
<string , string> output;
 
if (!processor.Initialize(&options , &output)) {
 fprintf
(stderr , "Error initializing processor.\n");
 
return 1;
 
}
 
if (!ProcessEntries(platform.get() , &processor , kSampleSize , kSampleRequests))
 
return 1;


 
PrintMap(&output);

 
}




 isolate
->Dispose();
 v8
::V8::Dispose();
 v8
::V8::ShutdownPlatform();
 
delete create_params.array_buffer_allocator;


}

DaManuell

unread,
Apr 2, 2019, 5:57:41 AM4/2/19
to v8-users
What is gisolate?

k g

unread,
Apr 2, 2019, 1:19:57 PM4/2/19
to v8-u...@googlegroups.com
Global var 

On Tue, Apr 2, 2019 at 17:57 DaManuell <manuel....@gmail.com> wrote:
What is gisolate?

--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/7cYhIZUOyjY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

DaManuell

unread,
Apr 5, 2019, 2:26:52 AM4/5/19
to v8-users
Is there a crash is you suppress that global from your source?


Le mardi 2 avril 2019 19:19:57 UTC+2, helloev a écrit :
Global var 

On Tue, Apr 2, 2019 at 17:57 DaManuell <manuel...@gmail.com> wrote:
What is gisolate?


helloev

unread,
Apr 5, 2019, 1:00:07 PM4/5/19
to v8-users
Reply all
Reply to author
Forward
0 new messages