/// <summary> /// Returns an engine to the pool so it can be reused /// </summary> /// <param name="engine">Engine to return</param> public virtual void ReturnEngineToPool(IJsEngine engine) { EngineMetadata metadata; if (!_metadata.TryGetValue(engine, out metadata)) { // This engine was from another pool. This could happen if a pool is recycled // and replaced with a different one (like what ReactJS.NET does when any // loaded files change). Let's just pretend we never saw it. engine.Dispose(); return; } metadata.InUse = false; var usageCount = metadata.UsageCount; if (_config.MaxUsagesPerEngine > 0 && usageCount >= _config.MaxUsagesPerEngine) { // Engine has been reused the maximum number of times, recycle it. DisposeEngine(engine); return; } if ( _config.GarbageCollectionInterval > 0 && usageCount % _config.GarbageCollectionInterval == 0 && engine.SupportsGarbageCollection() ) { engine.CollectGarbage(); } _availableEngines.Add(engine); }
public override void Dispose() { if (_engine.SupportsGarbageCollection) { _engine.CollectGarbage(); } _engine.Dispose(); }
public override void Dispose() { if (_engine.SupportsGarbageCollection) { try { _engine.CollectGarbage(); } catch (Exception) { Context.Debug(() => "Error collecting js garbage"); } } _engine.Dispose(); }
/// <summary> /// Returns an engine to the pool so it can be reused /// </summary> /// <param name="engine">Engine to return</param> public virtual void ReturnEngineToPool(IJsEngine engine) { if (!_metadata.ContainsKey(engine)) { // This engine was from another pool. This could happen if a pool is recycled // and replaced with a different one (like what ReactJS.NET does when any // loaded files change). Let's just pretend we never saw it. engine.Dispose(); return; } _metadata[engine].InUse = false; var usageCount = _metadata[engine].UsageCount; if (_config.MaxUsagesPerEngine > 0 && usageCount >= _config.MaxUsagesPerEngine) { // Engine has been reused the maximum number of times, recycle it. DisposeEngine(engine); return; } if ( _config.GarbageCollectionInterval > 0 && usageCount % _config.GarbageCollectionInterval == 0 && engine.SupportsGarbageCollection() ) { engine.CollectGarbage(); } _availableEngines.Add(engine); }