@@ -36,16 +36,26 @@ internal abstract class ActiveScriptJsEngineBase : IInnerJsEngine, IActiveScript
3636 /// </summary>
3737 private IntPtr _pActiveScript ;
3838
39+ /// <summary>
40+ /// Pointer to an instance of garbage collector
41+ /// </summary>
42+ private IntPtr _pActiveScriptGarbageCollector ;
43+
3944 /// <summary>
4045 /// Instance of native JavaScript engine
4146 /// </summary>
4247 private IActiveScript _activeScript ;
4348
4449 /// <summary>
45- /// Instance of ActiveScriptParseWrapper
50+ /// Instance of <see cref="IActiveScriptParseWrapper"/>
4651 /// </summary>
4752 private IActiveScriptParseWrapper _activeScriptParse ;
4853
54+ /// <summary>
55+ /// Instance of <see cref="IActiveScriptGarbageCollector"/>
56+ /// </summary>
57+ private IActiveScriptGarbageCollector _activeScriptGarbageCollector ;
58+
4959 /// <summary>
5060 /// Instance of script dispatch
5161 /// </summary>
@@ -134,6 +144,9 @@ protected ActiveScriptJsEngineBase(string clsid, JsEngineMode engineMode, string
134144 _activeScriptParse = new ActiveScriptParseWrapper ( _pActiveScript , _activeScript ) ;
135145 _activeScriptParse . InitNew ( ) ;
136146
147+ _pActiveScriptGarbageCollector = ComHelpers . QueryInterfaceNoThrow < IActiveScriptGarbageCollector > ( _pActiveScript ) ;
148+ _activeScriptGarbageCollector = _activeScript as IActiveScriptGarbageCollector ;
149+
137150 _activeScript . SetScriptSite ( this ) ;
138151 _activeScript . SetScriptState ( ScriptState . Started ) ;
139152
@@ -481,6 +494,18 @@ private void EmbedHostItem(string itemName, object value)
481494 } ) ;
482495 }
483496
497+ /// <summary>
498+ /// Starts a garbage collection
499+ /// </summary>
500+ /// <param name="type">The type of garbage collection</param>
501+ private void InnerCollectGarbage ( ScriptGCType type )
502+ {
503+ if ( _activeScriptGarbageCollector != null )
504+ {
505+ _activeScriptGarbageCollector . CollectGarbage ( type ) ;
506+ }
507+ }
508+
484509 /// <summary>
485510 /// Loads a resources
486511 /// </summary>
@@ -541,6 +566,9 @@ private void Dispose(bool disposing)
541566 _dispatch = null ;
542567 }
543568
569+ _activeScriptGarbageCollector = null ;
570+ ComHelpers . ReleaseAndEmpty ( ref _pActiveScriptGarbageCollector ) ;
571+
544572 if ( _activeScriptParse != null )
545573 {
546574 _activeScriptParse . Dispose ( ) ;
@@ -550,6 +578,7 @@ private void Dispose(bool disposing)
550578 if ( _activeScript != null )
551579 {
552580 _activeScript . Close ( ) ;
581+ Marshal . FinalReleaseComObject ( _activeScript ) ;
553582 _activeScript = null ;
554583 }
555584
@@ -796,6 +825,11 @@ public void EmbedHostType(string itemName, Type type)
796825 EmbedHostItem ( itemName , typeValue ) ;
797826 }
798827
828+ public void CollectGarbage ( )
829+ {
830+ InvokeScript ( ( ) => InnerCollectGarbage ( ScriptGCType . Exhaustive ) ) ;
831+ }
832+
799833 #endregion
800834
801835 #region IDisposable implementation
0 commit comments