Results 1 to 9 of 9

Thread: [Bug?] Ext.Component doesn't destroy context menus?

  1. #1
    Ext User
    Join Date
    Jul 2007
    Location
    Florida
    Posts
    9,996

    Default [Bug?] Ext.Component doesn't destroy context menus?

    Read Post #3 for additional info, but:

    I think Ext.Component needs a "cmenu" config and/or "addCmenu"/"removeCmenu" methods. That way Ext could manage and properly destroy context menus?

    If I monitor Ext.ComponentMgr.all.keys in firebug console I can see the number of keys steadily increasing when opening and closing the same window. Is this a sign that some of the dom isn't being destroyed properly?

    Just as an example, go to the desktop example and open and close the "Grid Window" icon. Each time it's closed and reopened looks like there's a few items that don't get cleared.

    I'm not asking for a solution, just wanting to know if this is something to be watchful for in general...is it a telltale sign, etc.

  2. #2
    Ext User
    Join Date
    Jul 2007
    Location
    Florida
    Posts
    9,996

    Default

    For the example I mentioned, it looks like the orphans belong to a context menu on buttons. I suspect (but have not verified) that maybe Ext.Button doesn't destroy the context menu when a button is removed.

  3. #3
    Ext User
    Join Date
    Jul 2007
    Location
    Florida
    Posts
    9,996

    Default

    This remedies the problem in the case of the desktop example.

    Code:
    Ext.override(Ext.Component, {
        /**
         * Destroys this component by purging any event listeners, removing the component's element from the DOM,
         * removing the component from its {@link Ext.Container} (if applicable) and unregistering it from
         * {@link Ext.ComponentMgr}.  Destruction is generally handled automatically by the framework and this method
         * should usually not need to be called directly.
         */
        destroy : function(){
            if(this.fireEvent("beforedestroy", this) !== false){
                this.beforeDestroy();
                if(this.rendered){
                    this.el.removeAllListeners();
                    this.el.remove();
                    if(this.actionMode == "container" || this.removeMode == "container"){
                        this.container.remove();
                    }
                }
                this.onDestroy();
                //destroy any context menu:
                if (this.cmenu) {
                    Ext.destroy(this.cmenu);
                }
                
                Ext.ComponentMgr.unregister(this);
                this.fireEvent("destroy", this);
                this.purgeListeners();
            }
        }
    });
    Is it the developer's responsibility to destroy any context menu or can Ext do this? I looked around a little and I couldn't see an easy way to reference the menu. Perhaps I'm brain dead, but context menu's are not like menu's which are registered to a particular variable right? In the case above I know the context menu was at this.cmenu, so easy enough. Ext knows other menus are at this.menu.

    There would need to me a convention applied that any context menu's are assigned to cmenu, or some kind of accessor method to retrieve any context menu's registered to that Component?

    Or easier, give Ext.Component a "cmenu" config and/or "addCmenu"/"removeCmenu" methods. That way Ext could manage these menus?

  4. #4
    Sencha Premium User
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,258

    Default

    Buttons do destroy associated menus. I don't really see why you'd add this for every component, because there's not often a time where you want a context menu on the whole component (tree, grid), you want it on specific elements within the component itself.

  5. #5
    Ext User
    Join Date
    Jul 2007
    Location
    Florida
    Posts
    9,996

    Default

    Can you show me where buttons destroy their context menus? I only found where menus are destroyed. As mentioned above, I couldn't find anywhere where context menus were being destroyed.

    I guess since there's no support for Ext adding the context menus that would seem reasonable why there would be no support for removing them as currently written (except of course firing an event which can be used to show the menu).

    I indicated having the context menu config property or methods on Component because I thought then those options would then be inherited by any subclasses of Component (including button, treepanel, gridPanel, etc.). Any class that exposes the event should/could expose the config/method so those context menus are destroyed automatically.

    Again, my proof of concept that there is a problem is the Desktop example since it uses context menus on Components that can be created and destroyed repeatedly (and thus leave orphans each time).

  6. #6
    Ext User
    Join Date
    Jul 2007
    Location
    Florida
    Posts
    9,996

    Default

    I posted this over the weekend so I wanted to bump this into the weekday forum watch.

    If this is not a bug, how are y'all typically handling this (any best practices to note)?

  7. #7
    Sencha User
    Join Date
    Apr 2012
    Location
    Austin, Texas
    Posts
    4

    Default

    Can you show me where buttons destroy their context menus? I only found where menus are destroyed.
    Button destroys its menu, but does not have any buit-in context menus. If you attach one, then as Evan said, it's up to you to destroy it. Ext will not search for context menus (or other things) that you may have added to a component at runtime.

  8. #8
    Ext User
    Join Date
    Jul 2007
    Location
    Florida
    Posts
    9,996

    Default

    Quote Originally Posted by brian.moeskau View Post
    Button destroys its menu, but does not have any buit-in context menus. If you attach one, then as Evan said, it's up to you to destroy it. Ext will not search for context menus (or other things) that you may have added to a component at runtime.
    Ok thanks Brian. Seems like it would be fairly easy for Ext to clean up these menus if a config or creation method were provided such that Ext knew what property to check and destroy. Maybe it's limited case but I'd suspect many out there don't realize they're creating some orphans like this.

    If such a fix is unlikely it would probably be valuable if there were some doc/wiki/thread/something that summarized some things like this the developer needs to watch out for. .... Or, in the case of the 'official' ext demos, the example should be updated to notify developers that the code as provided leaves orphans.

  9. #9
    Sencha User
    Join Date
    Nov 2008
    Posts
    35

    Default

    Please vote on the attached poll regarding context menus within Ext. I agree with MJ's opinion that it would be nice to see wider support of context menus and have an abstract level for configuration and methods of these menus.

    http://www.extjs.com/forum/showthread.php?t=55622

    Mjack

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •