The Wayback Machine - https://web.archive.org/web/20201220223254/https://github.com/paceholder/nodeeditor/issues/248
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

A possible leaking memory problem #248

Open
JesusCRIS90 opened this issue Jul 30, 2019 · 0 comments
Open

A possible leaking memory problem #248

JesusCRIS90 opened this issue Jul 30, 2019 · 0 comments

Comments

@JesusCRIS90
Copy link

@JesusCRIS90 JesusCRIS90 commented Jul 30, 2019

Trying to implement another cause of use, a block with a Custom Qwidget, I have found a memory problem that it is present in all the examples.

In the examples when a new block(Node) is created, a custom destructor is created. This destructor normally is empty. So nobody frees the Qwidget pointer. The curious here is that this problem is only present at the beginning when we run the application.

I have verified that when the scene is created, also an instance of each Node that we have set in the function “registerDataModel()” is created but immediately these instances are deleted. Here is the leaking problem, the Qwidget pointer of each node is not free.

If we try to solve this problem adding in the destructor adding the correspondent code “delete Qwidget”, we solve the problem but another worse problem it is created, a CRASH is produced when we delete (key Supr) a Node manually in our scene. This crash is due to that when we push the key Supr to delete a Node in the scene, first is deleted the pointer to the Qwidget and after the destructor of the Node, it is called. When the destructor tries to delete the pointer to the Qwidget, a crash in the application is produced because it is trying to delete a pointer(QWidget*) that already have been deleted.

I have found a way to solve both problems, but it is not the best solution. I have created a destructor with memory. The code for each destructor is the following:

`virtual ~CounterModel() override {

    static int amount = 0;
    if( amount == 0 )
    {
        delete _window;
        _window = nullptr;
        amount++;
    }
    else {
        _window = nullptr;
    }
} `

`

I think that this could be fixed in two ways:
1. When the keyword “Supr” is pressed, only delete the Node(Model), so the same model will make the action of cleaning the pointer of Qwidget.
2. Make an overload function as follow:
std::shared_ptr<QWidget*> embeddedWidget() override { return _window;}

Here an link to a video to explain better the error:
https://www.dropbox.com/s/wbdn8ooghyhoglc/Example?dl=0

Also it is possible that I am doing something wrong… In that case sorry for the inconvenience.

Daguerreo added a commit to Daguerreo/NodeEditor that referenced this issue Sep 14, 2020
Daguerreo added a commit to Daguerreo/NodeEditor that referenced this issue Sep 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
1 participant
You can’t perform that action at this time.