Opened 12 years ago

Closed 12 years ago

#3155 closed defect (wontfix)

dojo.event.connectRunOnce does not auto-disconnect

Reported by: guest Owned by: sjmiles
Priority: low Milestone:
Component: Events Version:
Keywords: Cc:
Blocked By: Blocking:

Description

Observed with Dojo 0.4.3.

dojo.event.connectRunOnce will insure that the event is only run a single time, but it does not automatically disconnect the connection. The docs for dojo.event.addAdvice state that the parameter maxCalls is "The maximum number of times this connection can be used before being auto-disconnected" which makes it sound like connections made with connectRunOnce will be auto-disconnected after a single execution.

Programmers who use connectRunOnce and don't realize that they must disconnect manually may unintentionally "leak" memory due to these orphaned connections.

The following sample demonstrates the problem. Note how the connection remains until it is manually disconnected.

<html>
<head>
    <script type="text/javascript" src="js/dojo/dojo.js"></script>
    <script type="text/javascript">

        function checkButtonClickHandler()
        {
            var button = dojo.byId("button");
            var after = button.onclick$joinpoint.after;
            if (after && after.length)
            {
                alert("handler is not disconnected.");

                // Disconnect it manually since connectRunOnce didn't disconnect it.
                dojo.event.disconnect(button, "onclick", onButtonClicked);
                if (after.length == 0)
                    alert("handler is now disconnected.");
            }
        }

        function onButtonClicked()
        {
            alert("button was clicked.");
            setTimeout(checkButtonClickHandler, 100);
        }

        dojo.addOnLoad(function(){
            var button = dojo.byId("button");
            dojo.event.connectRunOnce(button, "onclick", onButtonClicked);
        });
    </script>
</head>
<body>
Click Button to fire the event, after which it should be autodisconnected.
<button id="button">Button</button>
</body>
</html>

Change History (2)

comment:1 Changed 12 years ago by Adam Peller

Owner: changed from alex to sjmiles

no longer an issue in 0.9?

comment:2 Changed 12 years ago by sjmiles

Resolution: wontfix
Status: newclosed

No 'once' functionality in 0.9.

Note: See TracTickets for help on using tickets.