2009-06-18 7 views
1

유닛 통합 테스트 &을 프로파일 링하고 있는데, NHibernate.Transaction.AdoTransaction의 종료 자에 많은 시간을 소비했음을 알았습니다. 이는 제대로 폐기되지 않았 음을 의미합니다.왜 NHibernate AdoTransaction의 finalizer가 호출됩니까?

코드에서 AdoTransaction을 직접 사용하지 않으므로 NHibernate 내부의 다른 객체에 의해 사용되었을 가능성이 큽니다. 내가 버리는 걸 망설이는 어떤 생각? Sybase 데이터베이스에 액세스하는 동안 나는이 같은 문제가

public abstract class AbstractInMemoryFixture 
{ 
    protected ISessionFactory sessionFactory; 
    protected ILogger Logger { get; private set; } 
    static readonly Configuration config; 
    private static readonly ISessionFactory internalSessionFactory; 

    static AbstractInMemoryFixture() 
    { 
     config = new NHibernateConfigurator().Configure(NHibernateConfigurators.SQLiteInMemory()); 
     internalSessionFactory = config.BuildSessionFactory(); 
    } 

    [SetUp] 
    public void SetUp() 
    { 
     const string sqliteInMemoryConnectionString = "Data Source=:memory:;Version=3;Pooling=False;Max Pool Size=1;"; 
     var con = new SQLiteConnection(sqliteInMemoryConnectionString); 
     con.Open(); 
     new SchemaExport(config).Execute(false, true, false, true, con, System.Console.Out); 
     var proxyGenerator = new ProxyGenerator(); 

     sessionFactory = proxyGenerator.CreateInterfaceProxyWithTarget(internalSessionFactory, new UseExistingConnectionInterceptor(con)); 
     Logger = new NullLogger(); 

     ExtraSetup(); 
    } 

    [TearDown] 
    public void TearDown() 
    { 
     var con = sessionFactory.OpenSession().Connection; 
     if (con != null) 
     { 
      if (con.State == ConnectionState.Open) 
       con.Close(); 
      con.Dispose(); 
     } 
    } 

    private class UseExistingConnectionInterceptor :IInterceptor 
    { 
     private readonly SQLiteConnection connection; 

     public UseExistingConnectionInterceptor(SQLiteConnection connection) 
     { 
      this.connection = connection; 
     } 

     public void Intercept(IInvocation invocation) 
     { 
      if (invocation.Method.Name != "OpenSession" || invocation.Method.GetParameters().Length > 0) 
      { 
       invocation.Proceed(); 
       return; 
      } 
      var factory = (ISessionFactory) invocation.InvocationTarget; 
      invocation.ReturnValue = factory.OpenSession(connection); 
     } 
    } 
    protected virtual void ExtraSetup() { } 
} 

답변

0

:

여기 내 텍스트 고정입니다. 나는 이유를 모르거나 그것이 정말로 문제의 이유인지는 모르지만, 객체 닫기/처분과 관련된 \NHibernate\Transaction\AdoTransaction.cs (307 ~ 311 행)의 코드 중 일부는 잠시 동안 사용 중지 된 것처럼 보입니다. 불행히도, SVN의 비난 기능은 너무 많은 정보를주지 않습니다 : (