1

私には大きな疑問があります。問題は、私のクラスのメモリ不足例外です。しかし、ここで何かがおかしいようです。私はdllにクラスを持っています。

 public class MyClass : IDisposible
 {
     List<ClassA> a_classLists = new .....// new instance.
     List<ClassB> b_classLists = new .....// new instance.

     public string Method1(int IDValue)
     {
         // do here some web service call and get some XML data from it.
         // parse the xml.
         // Iterate through a for loop and add each node value to a_classLists
         // Usually contains 10 or 15 items

         Method2();  // from here calling another method
         FinalSaveToDB(); // finally save the data to DB
         return "";
     }

     private void Method2()
     {
         // do here some web service call and get some XML data from it.
         // Iterate through a forloop.
         // parse the xml. [large xml data. ie, image in binary format]
         // For each loop add image binary data and other xml to b_classLists
         // Usually it contains 50 or 60 such large lists.
     }

     private void FinalSaveToDB()
     {
         // using sqlbulkcopy, i am saving the data in the 2 lists to 2 different
         // tables in the DB.
         // Tab lock is mentioned in sqlbulk class.
         // Actually 2 sqlbulkcopy class for 2 lists.
         // Only 1 sql connection opens, then do the sqlbulkcopy. [there is no dataset or datareader]
         // sqlconnection closes. I am using "using" clause for sqlconnection, bulkcopy etc
         // these all are working fine.
     }

     private void Dispose()
     {
         // here nulling everything
         // proxy null
         // all the lists null....
     }
 }

これは、以下に示すように、リアクティブ フレームワークの Observable.Start メソッドを使用して 1000 回インスタンス化するクラスです...

  private IObservable<string> SendEmpDetails(Employee emp)
  {
    using (MyClass p = new MyClass())
    {
      return Observable.Start(() => p.Method1(emp.ID), Scheduler.ThreadPool);
    } 
   // here I hope it will call the Dispose and release all objects in the class.
  }

   // This EmployeeLists contains 1000 employee objects
   EmployeeLists.ToObservable().Select(x => SendEmpDetails(x).Select(y => new { emp = x, retval = y }))
                     .Merge(10)
                     .ObserveOn(Scheduler.CurrentThread)
                     .Subscribe(x =>
                     {
                        SendStatus(x.retval.Item1, x.retval);
                     });

それでも、なぜメモリ不足の例外が発生するのですか??? アプリを起動した後、200 番目 (またはそれ以上) の MyClass オブジェクトを処理すると、エラーがスローされます。

もう 1 つ言い忘れていましたが、VS 2010 と C# 4.0 (win7、64 ビット OS) を使用しています。

各アクティビティをログに記録する必要があります。[つまり、アプリが通過したすべてのプロセスを理解する必要があります]。SO i クラス [MyClass] レベルのプライベート文字列変数を宣言し、「このメソッドを呼び出した」、「この Web サービスから 5 つのレコードを取得した」などの各プロセスの詳細を割り当てます。

    logdata = Environment.Newline() + "This method has completed";

そのため、いくつかの評価が失敗したためにメモリ不足であるというエラーがここでスローされます。

そこで、VS のオプションから文字列評価のチェック ボックスをオフにしました。

繰り返しますが、無駄です。

そのため、文字列を StringBuilder に変更し、毎回アクティビティ文字列を追加しようとしました。

まだ駄目。何が問題なのかわかりません。

これは、すべてのスレッドが並行して動作しているためでしょうか? MyClass リソースを交換しますか ??? オブジェクトが解放されないのはなぜですか???

この件で私を助けてください。

4

0 に答える 0