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

How to delete an AsyncWorker pointer? #430

Closed
p3x-robot opened this issue Jan 23, 2019 · 5 comments
Closed

How to delete an AsyncWorker pointer? #430

p3x-robot opened this issue Jan 23, 2019 · 5 comments

Comments

@p3x-robot
Copy link

Hello!
How are you? I have a weird problem:

Napi::Value ArrayFireTestAsync(const Napi::CallbackInfo& info) {
 
  Napi::Function callback = info[0].As<Napi::Function>();

  // who is going to free up / delete this pointer???
  ArrayTestWorker* testWorker = new ArrayTestWorker(callback);
  testWorker->Queue();

  return  info.Env().Undefined();
}

It looks like the testWorker is a pointer, but when is it going to be freed up/deleted? The example was no info how to delete this pointer... Is this valid code?

@kevinGodell
Copy link

I was just playing with this exact thing last night. If you add the destructor method override in your asyncworker subclass and have it do something like std::cout << "async worker destruction" << std:endl; then you should see it print to the console when it completes its Execute and OnOK methods and is destroyed. I think it is destroyed by default unless you explicitly tell it not to be.

@p3x-robot
Copy link
Author

wow, thanks, i would have not thought it would be automatic for a pointer. so weird! that's all about my C++ .... 👍

@p3x-robot
Copy link
Author

i will wait for a little time if someone can explain what is happening... :)

@gabrielschulhof
Copy link
Contributor

The object instance does indeed self-destruct. We're adding a SuppressDestruct() method for cases where self-destruction is undesirable.

@p3x-robot
Copy link
Author

i was working for this kind of response. thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants