Closed pony5551 closed 5 years ago
c = null;
works, as well as c = 42;
. Just by assigning the variable a different value the previously stored instance's reference count is automatically decreased by ChakraCore, and later when the garbage collector sees 0 reference count it will call the registered finalizer callback which in turn frees the instance.
c=null; But this does not release the object!
c=null; But this does not release the object!
Not immediately - but that's by design. GC releases the object eventually. (It might be a good idea to extend the test suite with a proof.)
If you think you've found a bug please provide a MCVE. Thanks!
From my own experiments it works as expected. All native instances are released, either by the GC at some point during execution of the script or at the latest when the runtime is disposed.
I don't see where to call TNativeObject.AddRef and TNativeObject.Release!
In my opinion, is TNativeObject designed as an interface more appropriate? Because now you don't have to call JsDisposeRuntime and all of your new objects won't be thrown!
Maybe my idea is not necessarily correct, maybe you have other better way!
procedure Main; var DataModule: TDataModuleMain; begin ShowInfo;
DataModule := TDataModuleMain.Create(nil); try DataModule.Execute(ParamStrings); ReadLn; //At this point, new Console() is not released finally DataModule.Free; //When you get here, new Console() is released end; end;
I'm closing this issue with "works as designed". Please see the new finalizer tests in 48bea58.
var c = new Console(); //How to release here? delete c;//? c = null;//?