views:

48

answers:

1

I have an Qt application for symbian that receives gps data, stores it into a database and tries to post it to a server. First two steps work fine but continuous posting either crashes my application or kills my internet connection.

I have modified my application for debugging purposes so it only does post data to a server in every 10th second. Application runs fine for about 45-90min without any significant memory increase.

After that that I'll get an error from QNetworkReply saying "Cannot allocate memory".
Same time memory usage increases approximately 63500(bytes?).
On next upload I'll get reply that says "Invalid socket descriptor" and after that my QtCreator debug output is filled with "exception on 7 [will do setdefaultif(0) - hack]"

Anyone know what is going wrong here? I can't find errors from my upload code that could be causing this.

Here is my upload script.

void MainWindow::upload() {
    //Content of postData below. Using same data on every upload now when tracking the bug
    //[{"timestamp":"2010-10-01T17:10:27","latitude":62.1823321,"longitude":25.73226825,"user":6}]
    QByteArray postData; 

    QNetworkRequest request;
    request.setUrl(uploadUrl);
    this->qnam->post(request, postData);
}

void MainWindow::serviceRequestFinished(QNetworkReply* reply) {
    QByteArray bytes = reply->readAll();

    if (reply->error() == QNetworkReply::NoError)
    {
         //nothing in here when debugging
    } else {
        qDebug() << "-------Reply error: " + reply->errorString();
    }

    reply->deleteLater();
    updateHeapStats();
}

void MainWindow::updateHeapStats() { 
#ifdef Q_OS_SYMBIAN
        TInt mem, size, limit;
        User::Heap().AllocSize(mem);
        size = User::Heap().Size();
        limit = User::Heap().MaxLength();
        qDebug() << "**DEBUG MEMORY - > Memory:     " << QString::number(mem);
        qDebug() << "**DEBUG MEMORY - > Heap limit: " << QString::number(limit);
        qDebug() << "**DEBUG MEMORY - > Heap size:  " << QString::number(size);
#endif
}

Allmost forgot, I have tested this with Nokia N97mini, 5230 and 5800 and they all behave same way.

edit. Forgot to mention that when internet connection "dies" I still can see that 3G is on but connecting to internet with web-browser fails. When I close the application and try to connect to internet with browser it says "Web: Memory full, ..."(web requests from apps works fine) I'm using Nokia Energy profiler and it doesn't show any signs of memory being full. Even tested this and started 2 games, ovi maps and tons of other applications and they worked fine even though they consumed over 40MB of memory.

A: 

With the caveat that the only networking code I do in Qt is on a desktop platform and even then I need to look it up, I don't see anything obvious. I also know that in my own code deletelater() sometimes has a different idea of what "later" is than I do. I don't have time to look it up and may be wrong here, but I think deletelater() actually runs on the event thread, and if your event thread is always busy, when will it have time to delete the object? For debug purposes, I would replace deletelater() with delete (and really, there's no reason to use deletelater() unless you've got a parent/child relationship that you need to clean up, and there might be a way to manually remove the child from the parent so you don't need to worry about dangling pointers when you call delete).

I also don't know the accuracy of your memory consumption test. Does the allocated memory test refer to the current thread? The current process? Does a program received a "chunk" of memory from the heap that it simply managers on its own and it isn't permitted to use more than? I think you know this framework much better than I do; these are just some thoughts for you to try.

San Jacinto
Thanks for the reply. Forgot to mention but tested if reply gets deleted and it did everytime after requestFinished function. Only thing that is running between function calls is QTimer with 10sec timeout. I think application receives chunk of memory from a heap that can be defined by the user, user can also set maximum number how big heap can grow. I'm not totally sure if I'm right because haven't dealt with memory issues much
Harmiih