Hi,
While investigating some memory related issues in my application, I managed to reproduce what seems to be a problem. The following minimal application terminates on my PC after ~50 cycles and prints the following to console:
```
#
# Fatal error in heap setup
# Allocation failed - process out of memory
#
```
```
class Program
{
static void Main(string[] args)
{
for (int i = 0; i < 1000; i++)
{
using (V8ScriptEngine engine = new V8ScriptEngine())
{
Console.WriteLine("Created engine #{0}", i);
engine.Execute("function zz(){}");
var tmp = engine.Evaluate("zz");
}
}
}
}
```
Strangely, the memory usage doesn't seem high when it terminates.
I used both a Nuget package, and a manually built latest ClearScript + V8 with same results.
Any help will be greatly appreciated.
Thanks in advance again,
Ron
Comments: Hi Ron, No, that documentation still applies, although the wording may be a bit clumsy. All it's saying is that even if you've called `Dispose()`, the object cannot be garbage-collected until all references to it are gone. That's just the fundamental behavior of all managed objects. The problem here had to with _unmanaged_ objects - V8 runtimes in particular. Before the fix, script objects and compiled scripts held strong references to their V8 runtimes. Now those references are weak, and only script engines continue to use strong references. The result is that disposing a script engine immediately destroys the V8 runtime (unless that runtime is still in use by other script engines). Thanks again. This was an important fix!
While investigating some memory related issues in my application, I managed to reproduce what seems to be a problem. The following minimal application terminates on my PC after ~50 cycles and prints the following to console:
```
#
# Fatal error in heap setup
# Allocation failed - process out of memory
#
```
```
class Program
{
static void Main(string[] args)
{
for (int i = 0; i < 1000; i++)
{
using (V8ScriptEngine engine = new V8ScriptEngine())
{
Console.WriteLine("Created engine #{0}", i);
engine.Execute("function zz(){}");
var tmp = engine.Evaluate("zz");
}
}
}
}
```
Strangely, the memory usage doesn't seem high when it terminates.
I used both a Nuget package, and a manually built latest ClearScript + V8 with same results.
Any help will be greatly appreciated.
Thanks in advance again,
Ron
Comments: Hi Ron, No, that documentation still applies, although the wording may be a bit clumsy. All it's saying is that even if you've called `Dispose()`, the object cannot be garbage-collected until all references to it are gone. That's just the fundamental behavior of all managed objects. The problem here had to with _unmanaged_ objects - V8 runtimes in particular. Before the fix, script objects and compiled scripts held strong references to their V8 runtimes. Now those references are weak, and only script engines continue to use strong references. The result is that disposing a script engine immediately destroys the V8 runtime (unless that runtime is still in use by other script engines). Thanks again. This was an important fix!