How can I dispose a manage object that is added by AddHostObject api ?
Hello,
I am using ClearScript.V8 for my project. I want to dispose one of the object that I added using AddHostObject api.
public class A(){
int a;
public A(int a1){a=a1;}
}
..........
public ExecuteScript(){
var engine = new V8ScriptEngine();
engine.AddHostObject("Host", new A(1));
############## execute some script #####
**** how can i release host object "Host" ***
engine.AddHostObject("Host", new A(2));
############## execute some script #####
engine.dispose();
}
Hi @SiamAbdullah,
When you say "dispose" or "release", you seem to be referring to removing host objects from the script engine so that script code can no longer access them. Is that correct?
If so, then the answer is that AddHostObject is for installing permanent host APIs, particularly those requiring special HostItemFlags behavior. There's no RemoveHostObject, and that's by design.
If you're exposing an object that you'd like to remove later, do this instead:
engine.Script.Host = new A(1);
You can then reassign this property, or remove it completely like this:
engine.Execute("delete Host");
Good luck!
Thanks a lot.