About DirectGUI's destroy function...

Hello. I was wondering if I have to use the .destroy() function of DirectGUI on all of the gui elements that I’ve created even though they have the same parent.

For example:

DirectFrame1: parent = aspect2d

DirectButton1: parent = DirectFrame1

DirectButton2: parent = DirectFrame1

So… If I use .destroy() on DirectFrame1, will it remove DirectButton1 and DirectButton2 from the memory or will I also have .destroy() DirectButton1 and DirectButton2?

You just need to destroy the top parent.
This is what it (DirectGuiWidget class in DirectGuiBase.py) does :

    def destroy(self):
        if hasattr(self, "frameStyle"):
            if __dev__:
                guiObjectCollector.subLevel(1)
                guiObjectCollector.flushLevel()
                if hasattr(base, 'guiItems'):
                    if self.guiId in base.guiItems:
                        del base.guiItems[self.guiId]
                    else:
                        base.notify.warning(
                            'DirectGuiWidget.destroy(): '
                            'gui item %s not in base.guiItems' %
                            self.guiId)
            # Destroy children
            for child in self.getChildrenAsList():
                childGui = self.guiDict.get(child.getName())
                if childGui:
                    childGui.destroy()
                else:
                    # RAU since we added the class to the name, try
                    # it with the original name
                    parts = child.getName().split('-')
                    simpleChildGui = self.guiDict.get(parts[-1])
                    if simpleChildGui:
                        simpleChildGui.destroy()
                # messenger.send(DESTROY + child.getName())
            del self.guiDict[self.guiId]
            del self.frameStyle
            # Get rid of node path
            self.removeNode()
            for nodePath in self.stateNodePath:
                nodePath.removeNode()
            del self.stateNodePath
            del self.guiItem
            # Call superclass destruction method (clears out hooks)
            DirectGuiBase.destroy(self)

Though for dialogs, you have to use cleanup()