出于某种原因,我的 std::list 在我的程序执行过程中包含超过 1000000 个空对象(根据调试器)。
我在push_front()
and上设置了断点push_back()
,但它们都没有被调用 1000000 次,而我的实际代码只使用这两个函数。
恐怕我不知道要在这里复制什么代码 - 这是结果的实际位置System.AccessViolationException
,但是......好吧,我会复制任何人要求的任何代码。
//Model.h
struct Update {
public:
double pEgivenH, pE;
int E;
Update(double, double, int);
Update &operator=(const Update &rhs);
int operator==(const Update &rhs) const;
int operator<(const Update &rhs) const;
};
//UpdateButton.h
System::Void UpdateButton::UpdateButton_Click(System::Object^ sender, System::EventArgs^ e) {
double pEgivenH, pE;
int EID;
System::String^ pEHStr = pEHholder->Text;
System::String^ pEStr = pEholder->Text;
System::String^ eviStr = eviholder->Text;
pEgivenH = double::Parse(pEHStr);
pE = double::Parse(pEStr);
std::string evistr = msclr::interop::marshal_as<std::string>(eviStr);
EID = m->registerEvidence(evistr);
h->updateHypothesis(Update::Update(pEgivenH, pE, EID));//This line
}
//Model.cpp
double Hypothesis::updateHypothesis(Update u) {
history.push_back(u); //This line.
currentP *= u.pEgivenH / u.pE;
return currentP;
}
调试器数据:
A first chance exception of type 'System.AccessViolationException' occurred in System.Windows.Forms.dll
An unhandled exception of type 'System.AccessViolationException' occurred in System.Windows.Forms.dll
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
The program '[4500] AutoBayes.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).
编辑:我将调试代码添加到Hypothesis::updateHypothesis(Update)
. 新函数读取
//Model.cpp
double Hypothesis::updateHypothesis(Update u) {
System::Diagnostics::Debug::WriteLine(history.begin(), history.end());
history.push_back(u); //This line.
currentP *= u.pEgivenH / u.pE;
return currentP;
}
程序现在在调试线上崩溃了,我得到了
A first chance exception of type 'System.NullReferenceException' occurred in AutoBayes.exe
An unhandled exception of type 'System.NullReferenceException' occurred in AutoBayes.exe
Additional information: Object reference not set to an instance of an object.
堆栈跟踪表明它正在崩溃::end()
。