@skip('silverlight')
def test_event_lifetime():
 def keep_alive(o):
  pass
 def test_runner():
  import _weakref
  global called
  called = 0
  a = IronPythonTest.Events()
  def foo():
   global called
   called += 1
  foo.abc = a
  a.InstanceTest += foo
  a.CallInstance()
  AreEqual(called, 1)
  ret_val = _weakref.ref(foo)
  keep_alive(foo)
  import gc
  for i in xrange(10):
   gc.collect()
  a.CallInstance()
  AreEqual(called, 2)
  return ret_val
 func_ref = test_runner()
 import gc
 for i in xrange(10):
  gc.collect()
 Assert((not hasattr(func_ref, 'abc')))
 AreEqual(func_ref(), None)
 AreEqual(called, 2)

@ skip ( 'silverlight' ) def test_event_lifetime ( ) : def keep_alive ( o ) : pass def test_runner ( ) : import _weakref global called called = 0 a = IronPythonTest . Events ( ) def foo ( ) : global called called += 1 foo . abc = a a . InstanceTest += foo a . CallInstance ( ) AreEqual ( called , 1 ) ret_val = _weakref . ref ( foo ) keep_alive ( foo ) import gc for i in xrange ( 10 ) : gc . collect ( ) a . CallInstance ( ) AreEqual ( called , 2 ) return ret_val func_ref = test_runner ( ) import gc for i in xrange ( 10 ) : gc . collect ( ) Assert ( ( not hasattr ( func_ref , 'abc' ) ) ) AreEqual ( func_ref ( ) , None ) AreEqual ( called , 2 )
ensures that circular references between an event on an instance and the handling delegate dont call leaks and dont release too soon .