Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak on each http request #26

Open
delacko opened this issue Jun 21, 2020 · 1 comment
Open

Memory leak on each http request #26

delacko opened this issue Jun 21, 2020 · 1 comment

Comments

@delacko
Copy link

delacko commented Jun 21, 2020

I made a simple qml file with a timer that generates a HTTP GET request every 10 ms.
This causes memory leak at a rate of approximately 30-40 kB / second.

A smaller l

eak also exists if interval between requests is larger - ie. 200 ms request interval - leak seems proportional to number of requests.

Leak does not depend on the size of HTTP GET response. I tested with response of approximately 10 bytes, 100 kB, 10 MB.

Test environment: Linux Desktop, Qt 5.15.0

Sample:


import QtQuick 2.15
import QtQuick.Window 2.15
import com.cutehacks.duperagent 1.0 as Http

Window {
    id: window
    visible: true
    width: 640
    height: 480
    property int idx: 0
    Timer
    {
        id: requestTimer
        interval: 50
        repeat: true
        triggeredOnStart: true
        running: true
        onTriggered:
        {
            request(idx++)
            gc()
        }
    }
    Component.onCompleted:
    {
        Http.Request.config({
               cache: false
           });
    }
    function request(reqIdx){
            console.log("request initiated "+ reqIdx)

        var url = "http://localhost:9001/Screenshot_20200620_101301.png"
        Http.Request
        .get(url)
        .timeout(5000)
        .end(function(err, res) {
            console.log("request finished "+ reqIdx)
        });
    }
}
@mohammadhasanzadeh
Copy link
Contributor

mohammadhasanzadeh commented Jul 27, 2020

Hi, I think the reason for the memory leak on every request comes from the allocation of RequestPrototype instance, for example, you can see line #38 on duperagent.cpp:

QJSValue Request::get(const QJSValue &url, const QJSValue &data, const QJSValue &fn) const
{
    RequestPrototype *proto = new RequestPrototype(
                m_engine,
                RequestPrototype::Get,
                QUrl(url.toString()));

    if (data.isCallable()) {
        proto->end(data);
    } else if (!data.isUndefined()){
        proto->query(data);
    }

    if (fn.isCallable()) {
        proto->end(fn);
    }

    return proto->self();
}

it seems proto will never deleted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants