私の修士論文として、私は現在、X-Ray-Physicsのさまざまなタスク用のソフトウェアを作成しています。このソフトウェアは、Visual Studio 2015を使用してVisual C++ .Netで書かれており、32ビットシステム専用です。32ビットアプリケーションでSystem.OutOfMemoryExceptionが発生しました
今日、「System.Drawing.dllのSystem.OutOfMemoryException」というエラーが発生しました。 "大きな"ファイルをアプリケーションにインポートするときにエラーが発生します。
Visual Studio 2015のデバッグツールで、以下の関数内でエラーが発生していることがわかりました。デバッグツールによれば、エラーが発生するはずのコードの行にコメントを既に作成しています。コメントの下のコードの残りの部分のコメントを外してOutOfMemoryExceptionを解決しますが、私の目標にするべきではありません。それは、ソフトウェアをよりユーザフレンドリーにするだろう。
質問:誰かが以下の機能の中でエラーを見つけて(そして解決策を投稿する)、または良いヒントを持って問題を解決できますか?
追加情報が必要な場合は教えてください。私は、必要でないならば詳細に行きたくはありませんでした(10.000行以上のコード、多くの物理学)。
オリジナルコード:@Hansオルソンの考えと
void ManageComposition::CheckFontSetting(TreeNode^ treenode, bool checklines)
{
int result;
if (treenode->Nodes->Count!=0)
{
if ((treenode->Tag->GetType()->Name=="Element" && checklines) || treenode->Tag->GetType()->Name=="Composition")
{
IEnumerator^ treenodeenum = treenode->Nodes->GetEnumerator();
while (treenodeenum->MoveNext())
{
this->CheckFontSetting(safe_cast<TreeNode^>(treenodeenum->Current),checklines);
}
}
}
if (treenode->Tag->GetType()->Name=="Composition" && this->WithLines())
{
result=safe_cast<Composition^>(treenode->Tag)->CheckCalculationParamters(this->normalizeto100);
switch (result)
{
case 0:
treenode->BackColor=Color::LightGreen;
break;
case 1:
if (this->mode=="calculate intensities")
treenode->BackColor=Color::Red;
else if (this->mode=="calculate concentrations")
treenode->BackColor=Color::LightGreen;
else if (this->mode=="compare relative intensities")
treenode->BackColor=Color::Red;
break;
case 2:
if (this->mode=="calculate concentrations")
treenode->BackColor=Color::Red;
else if (this->mode=="calculate intensities")
treenode->BackColor=Color::LightGreen;
else if (this->mode=="compare relative intensities")
treenode->BackColor=Color::Red;
break;
case 3:
treenode->BackColor=Color::Red;
break;
}
}
// This is the point where the errors occur while handling large lists
// uncommenting the rest of this code will solve the error, but functionality will be lost
else if (treenode->Tag->GetType()->Name=="Element")
{
if (safe_cast<Element^>(treenode->Tag)->GetSymbol()!=treenode->Text)
{
if (safe_cast<Element^>(treenode->Tag)->GetIntensity(treenode->Text)!=0.0)
{
treenode->NodeFont=gcnew System::Drawing::Font(treenode->TreeView->Font,FontStyle::Bold);
treenode->Text=treenode->Text;
}
else if (safe_cast<Element^>(treenode->Tag)->GetGroupIntensity(treenode->Text)!=0.0)
{
treenode->NodeFont=gcnew System::Drawing::Font(treenode->TreeView->Font,FontStyle::Bold);
treenode->Text=treenode->Text;
}
else
{
treenode->NodeFont=gcnew System::Drawing::Font(treenode->TreeView->Font,FontStyle::Regular);
treenode->Text=treenode->Text;
} // Visual Studio debugging tool points on the condition below
if (safe_cast<Element^>(treenode->Tag)->IsGroupSelected(treenode->Text) || safe_cast<Element^>(treenode->Tag)->GetTransition(treenode->Text)->IsSelected())
{
treenode->BackColor=Color::Aquamarine;
}
else
{
treenode->BackColor=this->treeview->BackColor;
}
}
else
{
bool red=false;
if (this->mode=="calculate concentrations" || this->mode=="compare relative intensities")
{
if (safe_cast<Composition^>(safe_cast<Element^>(treenode->Tag)->owner)->IsRootComposition())
{
if (safe_cast<Element^>(treenode->Tag)->GetIntensitySum()==0.0)
{
if (safe_cast<Element^>(treenode->Tag)->GetConcentration()==0.0)
{
red=true;
}
}
}
else
{
if (safe_cast<Element^>(treenode->Tag)->GetIntensitySum()==0.0)
{
if (safe_cast<Element^>(treenode->Tag)->GetConcentration()==0.0)
{
red=true;
}
}
}
array<String^>^ dummy=safe_cast<Element^>(treenode->Tag)->GetRelevantLines();
if (dummy->Length>1)
{
int x;
String^ groupname=safe_cast<Element^>(treenode->Tag)->GetTransition(dummy[0])->GetGroup();
for(x=1;x<dummy->Length;x++)
{
if (groupname!=safe_cast<Element^>(treenode->Tag)->GetTransition(dummy[x])->GetGroup())
red=true;
}
}
}
if ((this->mode=="calculate intensities" || this->mode=="compare relative intensities")&& safe_cast<Element^>(treenode->Tag)->GetConcentration()==0.0)
red=true;
if (red)
treenode->BackColor=Color::Red;
else
treenode->BackColor=Color::LightGreen;
}
}
}
更新機能は:
void ManageComposition::CheckFontSetting(TreeNode^ treenode, bool checklines)
{
Font^ BoldFont = gcnew System::Drawing::Font(treenode->TreeView->Font, FontStyle::Bold);
Font^ RegularFont = gcnew System::Drawing::Font(treenode->TreeView->Font, FontStyle::Regular);
int result;
if (treenode->Nodes->Count!=0)
{
if ((treenode->Tag->GetType()->Name=="Element" && checklines) || treenode->Tag->GetType()->Name=="Composition")
{
IEnumerator^ treenodeenum = treenode->Nodes->GetEnumerator();
while (treenodeenum->MoveNext())
{
this->CheckFontSetting(safe_cast<TreeNode^>(treenodeenum->Current),checklines);
}
}
}
if (treenode->Tag->GetType()->Name=="Composition" && this->WithLines())
{
result=safe_cast<Composition^>(treenode->Tag)->CheckCalculationParamters(this->normalizeto100);
switch (result)
{
case 0:
treenode->BackColor=Color::LightGreen;
break;
case 1:
if (this->mode=="calculate intensities")
treenode->BackColor=Color::Red;
else if (this->mode=="calculate concentrations")
treenode->BackColor=Color::LightGreen;
else if (this->mode=="compare relative intensities")
treenode->BackColor=Color::Red;
break;
case 2:
if (this->mode=="calculate concentrations")
treenode->BackColor=Color::Red;
else if (this->mode=="calculate intensities")
treenode->BackColor=Color::LightGreen;
else if (this->mode=="compare relative intensities")
treenode->BackColor=Color::Red;
break;
case 3:
treenode->BackColor=Color::Red;
break;
}
}
// This is the point where the errors occur while handling large lists
// uncommenting the rest of this code will solve the error, but functionality will be lost
else if (treenode->Tag->GetType()->Name=="Element")
{
if (safe_cast<Element^>(treenode->Tag)->GetSymbol()!=treenode->Text)
{
if (safe_cast<Element^>(treenode->Tag)->GetIntensity(treenode->Text)!=0.0)
{
if (BoldFont) treenode->NodeFont = BoldFont;
treenode->Text=treenode->Text;
}
else if (safe_cast<Element^>(treenode->Tag)->GetGroupIntensity(treenode->Text)!=0.0)
{
if (BoldFont) treenode->NodeFont = BoldFont;
treenode->Text=treenode->Text;
}
else
{
if (!RegularFont) treenode->NodeFont = RegularFont;
treenode->Text=treenode->Text;
}
// Visual Studio debugging tool points to the condition below
if (safe_cast<Element^>(treenode->Tag)->IsGroupSelected(treenode->Text) || safe_cast<Element^>(treenode->Tag)->GetTransition(treenode->Text)->IsSelected())
{
treenode->BackColor = Color::Aquamarine;
}
else
{
treenode->BackColor=this->treeview->BackColor;
}
}
else
{
bool red=false;
if (this->mode=="calculate concentrations" || this->mode=="compare relative intensities")
{
if (safe_cast<Composition^>(safe_cast<Element^>(treenode->Tag)->owner)->IsRootComposition())
{
if (safe_cast<Element^>(treenode->Tag)->GetIntensitySum()==0.0)
{
if (safe_cast<Element^>(treenode->Tag)->GetConcentration()==0.0)
{
red=true;
}
}
}
else
{
if (safe_cast<Element^>(treenode->Tag)->GetIntensitySum()==0.0)
{
if (safe_cast<Element^>(treenode->Tag)->GetConcentration()==0.0)
{
red=true;
}
}
}
array<String^>^ dummy=safe_cast<Element^>(treenode->Tag)->GetRelevantLines();
if (dummy->Length>1)
{
int x;
String^ groupname=safe_cast<Element^>(treenode->Tag)->GetTransition(dummy[0])->GetGroup();
for(x=1;x<dummy->Length;x++)
{
if (groupname!=safe_cast<Element^>(treenode->Tag)->GetTransition(dummy[x])->GetGroup())
red=true;
}
}
}
if ((this->mode=="calculate intensities" || this->mode=="compare relative intensities")&& safe_cast<Element^>(treenode->Tag)->GetConcentration()==0.0)
red=true;
if (red)
treenode->BackColor=Color::Red;
else
treenode->BackColor=Color::LightGreen;
}
}
}
注:データを含むファイルをロード中にアプリケーションは、RAMの50 MB未満を使用しています。
どのように多くのノードをなどの代わりに、コードの をある?私はあなたがFontインスタンスをあまりにも多く割り当てると思うし、すべてのインスタンスはかなり重いです。 –
私は約45歳だと思います.10分を与えて、私はそれをチェックします。 – scherzkrapferl
これはあなたの問題には関係しませんが、そこに修正する必要があることがいくつかあります:1.文字列の代わりにenumを使用します(例: 'this-> mode'のために)。2.列挙子の代わりに' for each'ループを使用します。直接、3.リフレクションの代わりに 'dynamic_cast'を使うか、より良いのは多態性を使うことです。 –