Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8461625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:55:53+00:00 2026-06-10T13:55:53+00:00

I am creating a scientific application, that communicates with two devices (one via USB,

  • 0

I am creating a scientific application, that communicates with two devices (one via USB, one via serial port), takes data from them and present it in GUI. For unknown reason after running for several hours (2-5 maybe?) the whole system is suddenly starting to slow down, and after one or two minutes nothing is responding at all. The only solution then is to restart the PC with power button. The USB port communication is handled by code that came with this device, so it’s probably OK. The only hint I have is that reason might be in serial port communication, which I was implementing for the first time. But it may be anything else (e.g. GUI) as well. I’m running it on Scientific Linux 5. To open the serial port, I use:

tti::tti(const char* port)
{
fd = open(port,
        (O_RDWR | O_NOCTTY) & ~O_NONBLOCK); //opening the port
if (fd == -1)
{
    std::cout<<"error in tti::tti(const char* port) while opening port"<<std::endl;
}
else
{
    //setting parameters
    struct termios options; //create the struct
    tcgetattr(fd,&options); //get the current settings of the serial port
    cfsetispeed(&options,B9600); //set read and write speed to 19200 BAUD
    cfsetospeed(&options,B9600);
    options.c_cflag &= ~PARENB; //set no parity
    options.c_cflag &= ~CSTOPB; //set one stop bit
    options.c_cflag &= ~CSIZE; //clear current data size setting
    options.c_cflag |= CS8; //set 8 bit per work
    options.c_cc[VMIN] = 2; //minimum amount of characters to read
    options.c_cc[VTIME] = 10; //amount of time to wait for amount of data specified in VMIN in tenths of a second
    options.c_cflag |= (CLOCAL | CREAD); //don't allow changing of port control + enable the receiver
    if (tcsetattr(fd,TCSANOW,&options)!=0)
    {
        std::cout<<"error in tti::tti(const char* port) while setting options"<<std::endl;
    }
}
}

Then I use this code every ~3 seconds, 4 times in a row:

std::string tti::query(std::string input){
input+=10;

int bytes = 0;

bytes = write(hSerial, input.c_str(), input.size());

if(bytes < 1){
    std::cout<<"error in tti::send(std::string input) "<<std::endl;
    return "error: no bytes written";
}

bytes=0;
const int n=10;
char szBuffer[n +1]={0};
bytes = read(hSerial,szBuffer,n);
bytes = read(hSerial,szBuffer,n);
if(bytes < 1){
    std::cout<<"error in tti::query(std::string input)"<<std::endl;
    return "error: no bytes read";
}

std::string s2(szBuffer);
return s2;

}

Could You give me some advice how to find the reason for this behavior? I tried to run the app with valgrind and I found no memory leaks. I also tried to check the code with cppcheck and found nothing. The problem is that application does not crash – it’s running, but not responding. It has never happened in short-time run. The shortest time I waited for it to stop was 2 hours, but I also have run it 2-3 times for longer time without any problems.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T13:55:54+00:00Added an answer on June 10, 2026 at 1:55 pm

    Thank You for Your answers!

    I managed to find the source of increasing memory usage. Indeed the “top” command helped me a lot. It turned out, that I was allocating about 1MB per second without deleting it! After a few hours all physical memory of the PC was “eaten” by my application, so it stopped everything. Selectively disabling parts of my code and running “top”, I found the part responsible for the problem.

    The reason was somewhere else, not in serial port communication. In the application I had 6 objects (instances of the same class) responsible for real-time data plots. One of members of the plot holding class was a pointer to the plot itself. With every GUI refresh, I was overwriting the pointer with new plot object, without deleting the old one. I thought it would be deleted automatically, but I was wrong.

    void graphData::updateGraph () {
    
        delete m_graph; //THIS LINE WAS MISSING
        m_graph = new TGraph(m_xArray.GetSize(),m_xArray.GetArray(),m_yArray.GetArray());
    
        //(...) some more code in this function
    }
    

    Sounds pretty simple, but it took me a week to solve this problem. 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm thinking about creating a tool to visualize scientific data on a website. For
creating 20 viewcontrollers and calling them one after the other from the mainviewcontroller as
Creating My Windows Form Application and using ADO.Net as Data Access layer and SQL
I am creating 1D and 2D array from a file that contains lines that
i am newbie for Android Development. i don't have any idea for creating Scientific
Creating liquid layouts is an immense pain. Now, I totally understand that tables should
Creating a server-side socket will fail if I'm trying to use the same port
Creating a calculator-like dialog, I noticed that quickly clicking on a button in IE
Creating an installer for possible remote systems so that if they do not have
Creating a Drawable that is completely empty seems like a common need, as a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.