help icon indicating copy to clipboard operation
help copied to clipboard

node::ObjectWrap dispose method

Open tugrul opened this issue 8 years ago • 2 comments

https://github.com/nodejs/node/issues/22996

There is an allocated object inside of class constructor. https://github.com/tugrul/cryptian/blob/master/addon/src/node/algorithm.h#L29 and https://github.com/tugrul/cryptian/blob/master/addon/src/node/mode.h#L40.

I can't use destructor method because node::ObjectWrap have destructor method.

I think node::ObjectWrap can have Dispose placeholder method then call Dispose method by own destructor. By the way subclass of node::ObjectWrap can override Dispose method and able to free own allocated objects.

Is there an another way to free allocated objects by subclass of node::ObjectWrap ?

tugrul avatar Sep 21 '18 14:09 tugrul

I'm not sure that I'm following your problem.

Why don't you think you can add a destructor for your class inheriting from node::ObjectWrap? Just that is surely illustrated in the Doc's example in wrapping C/C++ objects here. Afterall, C++ is going to take care of chaining the destructor calls along the inheritance chain.

Thereafter, are you trying to propose that Dispose is added on the node::ObjectWrap interface? Its unclear to me that its needed (because of destructor chaining).

I really don't think we need another way!

Lastly, given you're making use of NAN in your code, would you not be better inheriting from Nan::ObjectWrap? ( https://github.com/nodejs/nan/blob/master/doc/object_wrappers.md )

shellberg avatar Sep 21 '18 16:09 shellberg

Thank you.

Before I tried add destructor my class and there was a warning messages "like non-virtual destructor have undefined behavior".

I tried again and i found missing destructor of my initialization object's class. I put virtual destructor placeholders and it solved that warning message.

https://github.com/tugrul/cryptian/commit/1e433038a8c2ac2eae3d3d5c9508ca91c40ee1a8

tugrul avatar Sep 21 '18 17:09 tugrul