After running the program in Qt Creator for some time, the "Application Output" in Creator printed "CSProxy Refcount XXX", and the program quit. exited with code 3
-
Dear all,
Sorry for my English, please help me. Can anybody tell me about the meaning of“CSProxy refcount XXX”?Here is my code:
void CreateDataFile() { //create four file every ten minutes QString interval = "$"; qWarning()<<"FileCreatebegin1:"<<QDateTime::currentDateTime(); QString data1; //data1.reserve(20000000); //if I allocate memory for data1,there are some changes to the statements printed by Application Output.See below. //1) for(int j=0;j<X_DataForSave.size();j++) //the data is from sensors,"DataForSave" is QStringList { data1.append(X_DataForSave.at(j)); data1.append(interval); data1.append(Y_DataForSave.at(j)); data1.append(interval); data1.append(Z_DataForSave.at(j)); data1.append(interval); } qWarning()<<"before qCompress QString1 size = "<<data1.size(); QByteArray ba1 = data1.toLatin1(); qWarning()<<"tolatin1:"<<QDateTime::currentDateTime(); //2)compress QByteArray combuffer1 = qCompress(ba1,-1);//using zlib //3)create file QString FileName1 = "1"+QDateTime::currentDateTime().toString("yyyyMMddhhmm")+".da";//data file QString filename1 =DirName+"/"+FileName1; QFile file1; file1.setFileName(filename1); if(file1.open(QIODevice::WriteOnly)) { file1.write(combuffer1); } file1.close(); qWarning()<<"FileCreateFinish1:"<<QDateTime::currentDateTime(); ......... There are three similar code snippets,It's just that the subscripts of each variable have changed,for example "data1" is changed to "data2", "FileCreateFinish1" is changed to "FileCreateFinish2". }
And here is what the "Application Output" prints:
...................
FileCreatebegin1: QDateTime(2021-07-1311:10:00.633 中国标准时间 Qt::LocalTime)
before qCompress QString1 size = 15796903 //emmm,maybe too large,About 30 mbyte.
tolatin1: QDateTime(2021-07-13 11:10:00.872 中国标准时间 Qt::LocalTime)
compress1: QDateTime(2021-07-13 11:10:01.773 中国标准时间 Qt::LocalTime)
FileCreateFinish1: QDateTime(2021-07-13 11:10:01.775 中国标准时间 Qt::LocalTime)
FileCreatebegin2: QDateTime(2021-07-13 11:10:01.778 中国标准时间 Qt::LocalTime)
//before qCompress QString2 size = 16452403 //if i dont't preallocate memory for data2,this sentence will not be printed
CSProxy refcount 42
11:10:05: G:/myprogram/build-myprogram-Qt_5_13_2_MinGW_32_bit_static-Debug/debug/myprogram.exe exited with code 3This problem doesn't happen often.The above function is triggered by a timer and is executed every 10 minutes.The problem can occur about two hours after the program runs.
I suspect it's due to a lack of memory,but the computer still has plenty of memory ,and I restarted the computer for a short time .
And I'm curious why Qt didn't report an error.The font of ""CSProxy refcount 42" is not red. -
Sorry for my English.
This problem is caused by qstringlist. In the code, I use qstringlist to store the original data collected by the sensor (the data type is int,I use qstring::number to convert int to qstring ), store it once per second, write the data to the file every ten minutes and empty the qstringlist. When the number of qstringlist elements exceeds 2 million (not fixed, related to the number of threads (running the same code: saving, writing files, emptying) and the number of such qstringlists), the program will crash automatically after running for a period of time (under MinGW compiler, the program will exit directly; under mvsc compiler, the program interface will turn white and get stuck).
I guess the reason is that the list will generate memory fragments. With the increase of program running time, such memory fragments will increase (there are many vectors with variable length in my program that will be generated and destroyed every second. Under the interaction of the two, there will be less and less large continuous memory left in the memory). Therefore, after the program runs for a period of time, when executing "for (int j = 0; J < x_dataforsave. Size(); j + +) {data1. Append...}", there is not enough continuous memory left for data1 (qstring stores its data in an array of char type). The program crashes because it can't allocate memory, and sometimes QT doesn't give a warning.
To solve this problem, I use qvector < int > to store the data collected by the sensor, and use fromrawbyte to get qbytearray.
Because I don't know much about the basic principle of computer, I have been perplexed by this problem for a long time. I hope this answer can be helpful to people with similar confusion.
Thank @ JonB for your help. I find It is not convenient to use debugger to locate such problems, because the time of program crash is not fixed, and the program has many threads, so it is difficult to locate them by breaking points; If I don't break the point, the program will exit automatically, and the debugger won't stay at the moment when the program crashes.
-
@karilito
I don't know where the messageCSProxy refcount 42
comes from. Maybe from within the zlib library called fromqCompress
. Createor won't show it in red as it's just a message from somewhere, not an error. Don't know what its significance is.You are running 32-bit. 30MB files/strings should be alright, unless you have larger ones. But I agree the fact that pre-allocation makes it work may be indicative. Your variables stay in scope during this function, I don't know just how many more byte arrays you have after the code you show. Reduce that, or factor into separate functions, to test.
Run your application in the debugger. See what happens when it "crashes".
Do you anywhere attempt to read the zlib-compressed file(s) you generate? Because your
QString FileName1 = "1"+QDateTime::currentDateTime().toString("yyyyMMddhhmm")+".da";//data file file1.open(QIODevice::ReadWrite)
is flawed and is likely to leave "corrupt" compressed files which zlib will error on if you try to deflate. This ought to be addressed regardless of your other error.
-
@JonB
Thanks for your help.
I've fixed my code and I am testing it again.
The compressed file is only writed once. And I changed the code “file1.open(QIODevice::ReadWrite)” to "file1.open(QIODevice::WriteOnly)".
After the code I show,the computer still have about 15504.4 MB free memory.I think the memory is sufficient. Is there too much memory fragmentation to allocate a large QString or QByteAarray?
I will debug my code carefully. Thansk again. -
@karilito
Good for theWriteOnly
.As I said, you should now run your code under the debugger. When it "crashes" it should break at the point of the crash. Look at the stack trace window to see where it is crashing and where in your code it was called from.
Another possibility is to test writing the uncompressed string to the file, and not calling
qCompress()
at all. That should tell you whether zlib is connected to the issue at all? -
Sorry for my English.
This problem is caused by qstringlist. In the code, I use qstringlist to store the original data collected by the sensor (the data type is int,I use qstring::number to convert int to qstring ), store it once per second, write the data to the file every ten minutes and empty the qstringlist. When the number of qstringlist elements exceeds 2 million (not fixed, related to the number of threads (running the same code: saving, writing files, emptying) and the number of such qstringlists), the program will crash automatically after running for a period of time (under MinGW compiler, the program will exit directly; under mvsc compiler, the program interface will turn white and get stuck).
I guess the reason is that the list will generate memory fragments. With the increase of program running time, such memory fragments will increase (there are many vectors with variable length in my program that will be generated and destroyed every second. Under the interaction of the two, there will be less and less large continuous memory left in the memory). Therefore, after the program runs for a period of time, when executing "for (int j = 0; J < x_dataforsave. Size(); j + +) {data1. Append...}", there is not enough continuous memory left for data1 (qstring stores its data in an array of char type). The program crashes because it can't allocate memory, and sometimes QT doesn't give a warning.
To solve this problem, I use qvector < int > to store the data collected by the sensor, and use fromrawbyte to get qbytearray.
Because I don't know much about the basic principle of computer, I have been perplexed by this problem for a long time. I hope this answer can be helpful to people with similar confusion.
Thank @ JonB for your help. I find It is not convenient to use debugger to locate such problems, because the time of program crash is not fixed, and the program has many threads, so it is difficult to locate them by breaking points; If I don't break the point, the program will exit automatically, and the debugger won't stay at the moment when the program crashes.