Home > Back-end >  Help take a look at the thread Exucute () function where there is a memory leak?
Help take a look at the thread Exucute () function where there is a memory leak?

Time:10-06

The main thread by timer trigger a second thread Sig_Collect per second, programs run for a period of time will prompt "... Raised exception class STD: : bad_alloc with message... ", CodeGuard no hint memory leaks, but open the task manager found that memory is rising, a 16 KB, or 32 KB, true is to find out where the leak, the delete all the delete, thread to Execute the last line is not automatically quit?? Should not require explicit release thread resources?

The child thread in the timer to establish
 void __fastcall TDataAcquireMainForm: : Timer1sTimer (TObject * Sender) 
{
Sig_Collect (false);//Sig_Collect threads to create
}
here is the thread of the Execute function body
 void __fastcall Sig_Collect: : Execute () 
{
//- Place thread code here -
FreeOnTerminate=true;
OnTerminate=DataAcquireMainForm - & gt; OnOverThread;
SiandWr - & gt; Acquire ();//critical section
If (CacheSize>
=1800){
If (Ev - & gt; WaitFor (INFINITE)==wrSignaled)//thread synchronization
{
The DeleteFile (DataDir + "DataCache \ \ Data. Dat");
CacheSize=0;
Ev - & gt; ResetEvent ();
}
The else
return;
}
Double dt=1.0/n_Fre;//time increment
Double * fData=https://bbs.csdn.net/topics/new double [n_FChannel - n_FHChannel];//a one-dimensional array
Double * sData=https://bbs.csdn.net/topics/new double [n_SChannel];//a one-dimensional array
* * ffData=https://bbs.csdn.net/topics/double (double) * * new double * [n_FChannel - n_FHChannel];//two dimensional array
for(int i=0; iFfData [I]=new double [n_Fre];
Int the File;//file handle
If (FileExists (DataDir + "DataCache \ \ Data. Dat"))
The File=FileOpen (DataDir + "DataCache \ \ Data. Dat", fmOpenWrite | fmShareDenyWrite);
The else
The File=FileCreate (DataDir + "DataCache \ \ Data. Dat");
FileSeek (File, 0, 2);
If (n_FChannel - n_FHChannel)
{
Int the nf=n_time % 20;
For (int k=nf * n_Fre; K<(nf + 1) * n_Fre; K++)
{
for(int i=0; i{
FData [I]=DataEngine (false, I, dt * k, n_Fre);
- nf * n_Fre ffData [I] [k]=fData [I];
}
FileWrite (File, fData, sizeof (n_FChannel - n_FHChannel) * (double));
}
Int minu=CacheSize/60;
Int the SEC=CacheSize % 60;
AnsiString datapointer=NULL;
Double FieldValue [8].
Int n_fre [6].//each frequency doubling frequency by
Double BFre [6].//the fundamental frequency amplitude
for(int i=0; i{
Datapointer=String (minu) + ":" + String (SEC);
FieldValue [0]=FormatFloat (" 00.000 ", Max (ffData [I], n_Fre)). ToDouble ();
FieldValue [1]=FormatFloat (" 00.000 ", min (ffData [I], n_Fre)). ToDouble ();
FieldValue [2]=FormatFloat (" 00.000 ", jfgen (ffData [I], n_Fre)). ToDouble ();
FieldValue [3]=FormatFloat (" 00.000 ", fcha (ffData [I], n_Fre)). ToDouble ();
FieldValue [4]=FormatFloat (" 00.000 ", piancha (ffData [I], n_Fre)). ToDouble ();
FieldValue [5]=FormatFloat (" 00.000 ", qiaodu (ffData [I], n_Fre)). ToDouble ();
FieldValue [6]=FormatFloat (" 00.000 ", fzhi (ffData [I], n_Fre)). ToDouble ();
FieldValue [7]=FormatFloat (" 00.000 ", sfzhi (ffData [I], n_Fre)). ToDouble ();
DateSeparator='/';
TimeSeparator=':';
STRSQL. Sprintf (" INSERT INTO time-domain eigenvalue table (channel, high frequency, time, data pointer, the maximum value, minimum value, RMS value, variance and deviation, kurtosis, peak, fengfeng value) VALUES (' % s', 'False', '% s',' % s', '% 6.3 f', '% 6.3 f', '% 6.3 f', '% 6.3 f', '% 6.3 f', '% 6.3 f', '% 6.3 f', '% 6.3 f) ",
NameFCha [I], DataTime DateTimeString (), datapointer, FieldValue [0], FieldValue [1], FieldValue [2], FieldValue [3], FieldValue [4], FieldValue [5], FieldValue [6], FieldValue [7]);
The Synchronize (CalcuEigen);//call the main interface of TADO components, use synchronized methods
Rfftbase2 (ffData [I], n_Fre);
BFre [1]=ffData [I] [0];
For (int k=0; K{
If (BFre [1] {
BFre [1]=ffData [I] [k].
N_fre [1]=k;
}
}
N_fre [0]=n_fre [1]/2; N_fre [2]=2 * n_fre [1]. N_fre [3]=3 * n_fre [1]. N_fre [4]=4 * n_fre [1]. N_fre [5]=5 * n_fre [1].
For (int k=0; K<6; K++)
{
If (n_fre [k] & gt; N_Fre/2-1)
N_fre [k]=n_fre/2-1;
BFre [k]=ffData [I] [n_fre [k]].
}
DateSeparator='/';
TimeSeparator=':';
STRSQL. Sprintf (" INSERT INTO frequency domain feature value table (channel, high frequency, time, data pointer, 1/2 frequency doubling [], the dominant frequency, frequency [2 times], [3 times frequency], [4 times frequency], [5 times frequency]) VALUES (' % s', 'False', '% s',' % s', '% 6.3 f', '% 6.3 f', '% 6.3 f', '% 6.3 f', '% 6.3 f', '% 6.3 f) ",
NameFCha [I], DataTime DateTimeString (), datapointer, BFre [0], BFre [1], BFre [2], BFre [3], BFre [4], BFre [5]);
The Synchronize (CalcuEigen);//call the main interface of TADO components, use synchronized methods
}
}

If (n_SChannel)
{
for(int i=0; iSData [I]=DataEngine (true, I, n_time, 0);
FileWrite (File, sData n_SChannel * sizeof (double));
}
FileClose (File);
If ((n_FChannel - n_FHChannel) | | n_SChannel)
{
HWND pWnd=FindWindow (" TMonitorForm ", "monitor screen");
If (pWnd)
SendMessage (pWnd, WM_MONITOR, 1, 0);
N_time + +;
CacheSize++;
}
The delete [] fData;
The delete [] sData;
for(int i=0; iThe delete [] ffData [I];
The delete [] ffData;
SiandWr - & gt; Release ();//release the critical section
N_end_Sig=true;
}

CodePudding user response:

Part to Execute the code block in turn and see if there is a corresponding memory leaks, judge leak from the part, sometimes may not be out in the Execute

CodePudding user response:

Open the task manager, I found the process using the handle to the number in the soaring

CodePudding user response:

You have two class file open operation, but only one file closed,

CodePudding user response:

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related