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

Deleting an item doesn't clean up its alias [v1.0.2] #1350

Closed
ysicg opened this issue Oct 19, 2021 · 10 comments
Closed

Deleting an item doesn't clean up its alias [v1.0.2] #1350

ysicg opened this issue Oct 19, 2021 · 10 comments
Assignees
Labels
priority: high high priority state: ready Fixed/Added and will be present in an upcoming release type: bug bug

Comments

@ysicg
Copy link

ysicg commented Oct 19, 2021

Version of Dear PyGui

Version: 1.0.2
Operating System: Ubuntu 20.04

To Reproduce

Create an item with an alias and delete it:

import dearpygui.dearpygui as dpg

dpg.create_context()
with dpg.window():
    dpg.add_text("", tag="an_alias")
    dpg.delete_item("an_alias")
    dpg.does_item_exist("an_alias") #returns False as expected
    if dpg.does_alias_exist("an_alias"):
        print("Kill me please!")

dpg.destroy_context()

Expected behavior

does_alias_exist(alias) to return False, as it did in v0.8.64.

@ysicg ysicg added state: pending not addressed yet type: bug bug labels Oct 19, 2021
@Pcothren
Copy link
Collaborator

it appears that this is only happens when an item is created and deleted before DPG starts that the alias is not cleaned up

import dearpygui.dearpygui as dpg

dpg.create_context()

def check_state():
    dpg.delete_item('an_new_alias')
    print(f"More Text Item (After deleted): {dpg.does_item_exist('an_new_alias')}")
    print(f"More Text Alias (After deleted): {dpg.does_alias_exist('an_new_alias')}")

with dpg.window()as mainWin:
    dpg.add_text("Some Text", tag="an_alias")
    dpg.add_text("More Text", tag="an_new_alias")

    print(f"Some Text Item: {dpg.does_item_exist('an_alias')}")
    print(f"Some Text Alias: {dpg.does_alias_exist('an_alias')}")
    dpg.delete_item('an_alias')
    print(f"Some Text Item (After deleted): {dpg.does_item_exist('an_alias')}")
    print(f"Some Text Alias (After deleted): {dpg.does_alias_exist('an_alias')}")

    dpg.add_button(label="check state", callback=check_state)

dpg.create_viewport()
dpg.show_viewport()
dpg.setup_dearpygui()
dpg.start_dearpygui()
dpg.destroy_context()

@ysicg
Copy link
Author

ysicg commented Oct 19, 2021

If we delete the whole window instead in check_state(),

dpg.delete_item(mainWin)

Both aliases remain uncleaned.

@hoffstadt
Copy link
Owner

It appears the aliases are only removed if the app has actually started up. We will need to cover this case.

@ysicg The workaround is to manually remove the alias: dpg.remove_alias("an_alias") after deleting the item.

@Pcothren
Copy link
Collaborator

Pcothren commented Nov 4, 2021

// in case item registry is destroyed
if (GContext->started)
{
RemoveAlias(*GContext->itemRegistry, _alias, true);
CleanUpItem(*GContext->itemRegistry, _uuid);
}

commenting out this check will fist this example: #1350 (comment)

probably dig deeper into why this check was implemented and when, could have been before the context was created explicitly in which case it may not be needed anymore, maybe try and find pr and issue that was related to this fix

@Pcothren
Copy link
Collaborator

Pcothren commented Nov 4, 2021

goes back to commit eb80b71 and then is replaced with

// in case item registry is destroyed
if (GContext->started)
{
CleanUpItem(*GContext->itemRegistry, _uuid);
RemoveAlias(*GContext->itemRegistry, _alias, true);
}

from

		// in case item registry is destroyed
		if (mvApp::IsAppStarted())
		{
			CleanUpItem(*mvApp::GetApp()->itemRegistry, _uuid);
			RemoveAlias(*mvApp::GetApp()->itemRegistry, _alias, true);
		}

and
mvApp::IsAppStarted()

was originally implemented in 2c6f1b6

@josevnz
Copy link

josevnz commented Nov 10, 2021

Hello, you can use the following code to reproduce the issue:

#!/usr/bin/env python
#pylint: disable=import-error
#pylint: disable=invalid-name
"""
Simple usage of table with dynamic rows
"""

import dearpygui.dearpygui as dpg


if __name__ == "__main__":
    tag="mytableid"
    dpg.create_context()
    with dpg.window(label="main_window"):
        with dpg.table(header_row=True, resizable=True, tag=tag, parent="main_window"):
            dpg.add_table_column(label="Name", parent=tag)
            dpg.add_table_column(label="Size (bytes)", default_sort=True, parent=tag)
            for row in range(0, 100):
                with dpg.table_row(parent=tag):
                    dpg.add_text("col1")
                    dpg.add_text("col2")
        #dpg.delete_item(tag, children_only=False)
        #dpg.remove_alias(tag)
        with dpg.table(header_row=True, resizable=True, tag=tag):
            dpg.add_table_column(label="Name", parent=tag)
            dpg.add_table_column(label="Size (bytes)", default_sort=True, parent=tag)
            for row in range(0, 4):
                with dpg.table_row(parent=tag):
                    dpg.add_text("col1")
                    dpg.add_text("col2")

    dpg.create_viewport(title='RPM Quick query tool', width=500)
    dpg.setup_dearpygui()
    dpg.show_viewport()
    dpg.start_dearpygui()
    dpg.destroy_context()

If you uncomment the following lines

        dpg.delete_item(tag, children_only=False)
        dpg.remove_alias(tag)

Then the table works fine.

@hoffstadt
Copy link
Owner

Fixed in next release.

@hoffstadt hoffstadt added the state: ready Fixed/Added and will be present in an upcoming release label Nov 29, 2021
@hoffstadt hoffstadt self-assigned this Nov 29, 2021
hoffstadt added a commit that referenced this issue Dec 10, 2021
* fix: alias cleanup #1350

* fix: item type string change from 1.1.2
@iBenji
Copy link

iBenji commented Aug 17, 2023

Still problem exist.
But this issue also could be solved by doing this:

table_window = None

def get_ClientsTable():
    global table_window
    if table_window is not None:
        dpg.delete_item(table_window)
        table_window = None

    with dpg.window(label="Clients List", width=gVars.window_width/1.5, height=gVars.window_height, no_collapse=True) as table_window:
        with dpg.menu_bar():
            dpg.add_menu_item(label="Add row")
        with dpg.table(header_row=True, tag="cTable"):
            dpg.add_table_column(label="Date", id="date")
            dpg.add_table_column(label="Number", id="pc")
            dpg.add_table_column(label="Price", id="price")
            dpg.add_table_column(label="Admin", id="admin")

@equidna
Copy link

equidna commented Nov 17, 2023

It seems to exist some type of memory leak when the deleted item is a node editor. When repeatedly deleting and adding a node editor item the active allocations keep growing. Is this normal? Can anyone confirm this? Thanks.

@georgedimitriadis
Copy link

I have the same problem. I have a node editor and I call up also dpg.show_item_registry() to see what is goign on. When I create and delete a Node (and remove its alias) the registry keeps showing the Node so as I keep doing this the registry keeps growing. The Node though does disapear from the editor.
If I use the registry window's Delete button then the item gets deleted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: high high priority state: ready Fixed/Added and will be present in an upcoming release type: bug bug
Projects
None yet
Development

No branches or pull requests

7 participants