Memory leak

Find and share HowTos to various installations / configurations!
4 posts • Page 1 of 1
Nikolay
Posts:34
Joined: Tue Aug 21, 2012 7:10 am

Memory leak

Post by Nikolay »

Dear colleagues.
We have a serious problem. We wrote a program that accepts data from 200 devices using the ModBus protocol. The data from these devices come with a high frequency and represent a telegram that is parsed on the server side, the data received are recorded in Raima. The problem is that we are experiencing memory overflows. Help please understand the problem.

Code: Select all

#uses "CtrlADO"

main() {
 while(1) {
	  blob s;
	  dyn_string path_to_section, path_to_pos_in_section, signal_name;
	  dyn_blob First_stack_value;
	  string dpName, dpName_for_para, Descr, normal_data = "";
	  dyn_int bit_number;
	  uint id_skv, type_tel, number_tel, datasets_cont, reg_cont, ts_min, ts_sec, status_c, analog_c, name_reg, val_reg, val_reg1, val_reg2, hours, mins, secs, msec, Sig_int=0, Exp_int=0, Man_int=0;
	  int g=0, reg_pos=16, discret_value; 
	  float analog_value = 0;      
	  int rc;
	  dbConnection conn;
	  dbCommand cmd;
	  dbRecordset rs;
	  dyn_anytype sql_result;  
	  time t;     
	  dpGet("System1:Settings.Buffer.Stack:_original.0._value", First_stack_value);
 if(dynlen(First_stack_value)>0){
	  s = First_stack_value[dynlen(First_stack_value)];
	  blobGetValue(s, 0, id_skv ,2 ,TRUE);
	  blobGetValue(s, 2, type_tel ,2 ,TRUE);
	  blobGetValue(s, 4, number_tel ,2 ,TRUE);
	  blobGetValue(s, 6, datasets_cont ,1 ,TRUE); // it's used
	  blobGetValue(s, 7, reg_cont ,1 ,TRUE);
	  blobGetValue(s, 8, ts_min ,2 ,TRUE);
	  blobGetValue(s, 10, ts_sec ,2 ,TRUE);
	  blobGetValue(s, 12, status_c ,1 ,TRUE);
	  blobGetValue(s, 14, analog_c ,2 ,TRUE);  
  // 14 15 - zero
  // 000A - 16
  // 3100 - 18
  // ~16 - id, 17 - value  
  //DebugN(status_c, "-------", analog_c);    
  if(type_tel != 1049) {  
	  hours = ts_min / 60;
	  mins = ts_min - hours*60;
	  secs = ts_sec / 1000;
	  msec = ts_sec - secs*1000;	  
	  t=getCurrentTime();
	  sprintf(normal_data,"%02d:%02d:%02d:%03d",hours,mins,secs,msec);	  
	  normal_data = formatTime("%Y-%m-%d", t) + " " + normal_data;

  while(g

leoknipp
Posts:2928
Joined: Tue Aug 24, 2010 7:28 pm

Re: Memory leak

Post by leoknipp »

Can you please give the information which process has a "memory leak".
Also please check if errors are reported in the PVSS_II.log file which refer to the process which has the "memory leak".

Best Regards
Leopold Knipp
Senior Support Specialist

kilianvp
Posts:443
Joined: Fri Jan 16, 2015 10:29 am

Re: Memory leak

Post by kilianvp »

why you open and close the DB connection so often?

You use Linux? unixODBC has a few issues with memory leaks.

Just keep the connection open :)

Nikolay
Posts:34
Joined: Tue Aug 21, 2012 7:10 am

Re: Memory leak

Post by Nikolay »

Dear colleagues, I apologize for the long absence, I was sent to work on another project. The other day I solved this problem with a memory leak. The trouble was in SQL transactions. On the places where I used ordinary sql commands, I used threads, and already in these threads did sql commands. And everything worked as it should =) Thank you all ;-)

4 posts • Page 1 of 1