Bug Tracker

Changes between Initial Version and Version 1 of Ticket #8266


Ignore:
Timestamp:
Feb 14, 2011, 7:57:32 AM (9 years ago)
Author:
jitter
Comment:

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 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 example

I hope the explanation was sufficiently clear.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #8266

    • Property Priority changed from undecided to low
    • Property Status changed from new to closed
    • Property Component changed from unfiled to queue
    • Property Resolution changed from to worksforme
  • Ticket #8266 – Description

    initial v1  
    1 I found ticket [#4127] with this same problem back in version 1.3 and it seems to have been reintroduced in version 1.5.
     1I found ticket #4127 with this same problem back in version 1.3 and it seems to have been reintroduced in version 1.5.
    22
    33Here is a demo: http://jsfiddle.net/Mottie/GfWFM/