Side navigation
#8266 closed bug (worksforme)
Opened February 14, 2011 05:50AM UTC
Closed February 14, 2011 12:57PM UTC
Last modified February 14, 2011 02:53PM UTC
Queue type must be "fx" or it breaks
Reported by: | Motty | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | 1.next |
Component: | queue | Version: | 1.5 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
I found ticket #4127 with this same problem back in version 1.3 and it seems to have been reintroduced in version 1.5.
Here is a demo: http://jsfiddle.net/Mottie/GfWFM/
In the demo, switch the jQuery version from 1.4.4 to 1.5 to see the problem, then change the queName variable from 'fx2' to 'fx'.
Attachments (0)
Change History (2)
Changed February 14, 2011 12:57PM UTC by comment:1
_comment0: | Thanks for taking the time to contribute to the jQuery project by writing a bug report and providing a test case! \ \ After checking your report and test case I came to the conclusion that this isn't a bug. The behavior you see is caused by a bug fix in 1.5 (for a memory leak that was present in 1.4.4). Check this [https://github.com/jquery/jquery/commit/80af46e8ffe8292e0af0537db6c7e89019e5edba commit] for the code change. \ \ Your code only worked in 1.4.4 because the empty queue object wasn't removed from the cache in 1.4.4 (thus leaking memory). In 1.5 with the bug fix your code hits a "race condition", if you have some understanding of the inner workings of queue/dequeue you can verify that yourself by looking at this [https://github.com/jquery/jquery/blob/1.5/src/queue.js#L45-52 piece of code]. \ \ When you dequeue the last function on the queue the queue is empty, this last function calls `startLoop` which re-fills the queue and calls next which logs "7" and dequeues the first function on the stack which executes a `setTimeout`. Now the code "returns" and unwinds the call-stack and ends up in `.dequeue` again where it started the execution of the "last" function on the queue. It still knows that the queue was empty and thus removes it. When the `setTimeout` function runs the queue is no longer there (=empty) your code logs 0 and ends. \ \ So all you need to do is wrap the `startLoop` call in a setTimeout do as shown in this [http://jsfiddle.net/jitter/PUWQe/ example] → 1297688343717635 |
---|---|
component: | unfiled → queue |
description: | I found ticket [#4127] with this same problem back in version 1.3 and it seems to have been reintroduced in version 1.5. \ \ Here is a demo: http://jsfiddle.net/Mottie/GfWFM/ \ \ In the demo, switch the jQuery version from 1.4.4 to 1.5 to see the problem, then change the queName variable from 'fx2' to 'fx'. \ \ → I found ticket #4127 with this same problem back in version 1.3 and it seems to have been reintroduced in version 1.5. \ \ Here is a demo: http://jsfiddle.net/Mottie/GfWFM/ \ \ In the demo, switch the jQuery version from 1.4.4 to 1.5 to see the problem, then change the queName variable from 'fx2' to 'fx'. \ \ |
priority: | undecided → low |
resolution: | → worksforme |
status: | new → closed |
Changed February 14, 2011 02:53PM UTC by comment:2
Thank you sir!
Thanks for taking the time to contribute to the jQuery project by writing a bug report and providing a test case!
After checking your report and test case I came to the conclusion that this isn't a bug. The behavior you see is caused by a bug fix in 1.5 (for a memory leak that was present in 1.4.4). Check this commit for the code change.
Your code only worked in 1.4.4 because the empty queue object wasn't removed from the cache in 1.4.4 (thus leaking memory). In 1.5 with the bug fix your code hits a "race condition", if you have some understanding of the inner workings of queue/dequeue you can verify that yourself by looking at this piece of code.
When you dequeue the last function on the queue the queue is empty, this last function calls
startLoop
which re-fills the queue and calls next which logs "7" and dequeues the first function on the stack which executes asetTimeout
. Now the code "returns" and unwinds the call-stack and ends up in.dequeue
again where it started the execution of the "last" function on the queue. It still knows that the queue was empty and thus removes it. When thesetTimeout
function runs the queue is no longer there (=empty) your code logs 0 and ends.So all you need to do is wrap the
startLoop
call in a setTimeout do as shown in this exampleI hope the explanation was sufficiently clear.