我正從下面的C++腳本獲取內存堆消息。如果我刪除數組重新分配,錯誤消失。所以這個bug可能在代碼的釋放部分。我不能能夠找出內存堆問題C++,動態分配多維數組
if(harmonic_type =='a')
{
double ** harmonic_content = new double *[number_of_harmonics_required_to_monitor]();
for (int i=0;i<number_of_harmonics_required_to_monitor+1;i++)
{
harmonic_content[i] = new double [2]();
}
harmonic_content = harmonic_detector(waveformdata,number_of_samples,samplingrate_Hz, fundamental_frequency_Hz, number_of_harmonics_required_to_monitor,harmonic_type);
for (int i=1;i<number_of_harmonics_required_to_monitor+1;i++)
{
cout<<" Harmonic order "<< i << "::::" << harmonic_content[i][0] << " Hz ::::"<<harmonic_content[i][1] << " :::: "<<harmonic_content[i][2]<<endl;
}
for (int i=0;i<number_of_harmonics_required_to_monitor+1;i++)
{
delete [] harmonic_content [i];
}
delete [] harmonic_content;
}