Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#12599 closed bug (notabug)

jqXHR object becomes undefined over a period of time - IE8 reports error 'jqXHR' is null or not an object

Reported by: sabapathy.k@… Owned by: sabapathy.k@…
Priority: undecided Milestone: None
Component: unfiled Version: 1.5.2
Keywords: Cc:
Blocked by: Blocking:


In my application I use jquery ajax to fetch the device data at 1 second interval. The device has wince os and the web pages are hosted by httpd web server. We could observe the issue after running the device 2 or more days with web clients connected. The IE status bar displays an error “’jqXHR’ is null or not an object” or 'jqXHR'is undefined (in jquery-1.5.2.js, line no. 6819). I am also catching the request errors by using the jquery error function. But this error reported by IE couldn’t be captured by the error function

Further analyzing I understood there was an improvement done to IE8 garbage collector, to mitigate the circular reference memory leaks. There is a circular reference (closure) present in the ajax function of Jquery (jqXHR referenced in setTimeout handler at line no. 6819).

Timeout if ( s.async && s.timeout > 0 ) {

timeoutTimer = setTimeout( function(){

jqXHR.abort( "timeout" );

}, s.timeout );


Somehow the IE GC clears the jqXHR object at somepoint, even though it is referenced, this should not be the case with the earlier versions of IE.

To prevent IE GC from clearing this object, I declared a global variable and referenced the ajax object, thinking that it will prevent the GC from clearing it, since it has been made as a reachable object now.

jqxhr_obj = $.ajax( { .... });

Unfortunately even this didn't solve the problem.

I think the jquery implementation needs a change in this case to resolve the issue. jqXHR object should not be directly referenced from the setTimeout handler; this issue could be related to variable scope. Kindly analyze and provide your valuable comments.

Refer post:http://forum.jquery.com/topic/jqxhr-is-null-or-not-an-object-error-11-7-2012#14737000003491015

Thanks much!

Change History (10)

comment:1 Changed 11 years ago by Rick Waldron

Owner: set to sabapathy.k@…
Status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket!

Additionally, be sure to test against the "jQuery (edge)" version to ensure the issue still exists. To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/ Open the link and click to "Fork" (in the top menu) to begin.

comment:2 in reply to:  1 Changed 11 years ago by sabapathy.k@…

Status: pendingnew

Replying to rwaldron: Hello,

As per your request I have updated the sample code in the fiddle http://jsfiddle.net/33eKJ/1/ for you to assess the issue better.

But unfortunately I couldn't use the function setInterval in the fiddle, I use this to send periodic AJAX requests.

Please remember, as I have mentioned in the issue description this issue occurs randomly after 2 or 3 days running the web client continuously in IE8. Kindly analyze and let me know the problem.

Let me know for clarifications.

Thanks & regards, Sabapathy K

comment:3 Changed 11 years ago by dmethvin

Resolution: notabug
Status: newclosed

This isn't a problem that has ever been reported before, so whatever it is must be very rare and most likely not a jQuery bug.

Not sure why you "Re-initialize the objects" since they are not yours to modify. Is there some jQuery documentation that said to do that?

In general it is a very bad idea to fire off requests using setInterval unless your code is prepared to deal with the possibility that previous requests have not completed. If, for example, there was a temporary break in network connectivity, multiple requests will be queued. The fact that it's hitting the jqXHR.abort( "timeout" ); line means at least one request has timed out.

Here's a test case that creates the situation quickly.


I don't think this is a jQuery bug, but if it is we'd need you to isolate it better and remove the questionable code.

Last edited 11 years ago by dmethvin (previous) (diff)

comment:4 in reply to:  3 Changed 11 years ago by sabapathy.k@…

Replying to dmethvin:Hello dmethvin,

The bug could be because of the change in IE8 browser's Garbage collector update (as I have mentioned already). I could not see this issue in IE6.

I suspect the problem is because, "jqXHR" object which is defined local to the function "ajax"(line:6466) is referenced in the setTimeout handler. The setTimeout handler executes only after the timeout specified elapses. Won't there be any problem if the timeout was set to a greater value? What if the GC scans such type of closures and clears it to avoid any memory leak? Of course this not a usual case.

Can you please provide me a solution/workaround to prevent this issue occurring? I believe if this object had a global scope, this issue wouldn't have occurred.

Regarding your other questions regarding my implementation: It is ensured that only one requests hit the server at a time. The next request will not be sent unless the previous one's state is known.

I do Re-initialize objects only after the request status is completely known. I believe there should not be a problem here. I perform this just to ensure that there is no memory leak. Kindly correct me if I am wrong.

Thanks in advance for your help!

Best regards, Sabapathy K

comment:5 Changed 11 years ago by dmethvin

Your code does this, modifying an object it does not own:

    xmlhttp_obj.onreadystatechange = null;        
    xmlhttp_obj.abort = null;    

The error occurs here:

jqXHR.abort( "timeout" );

Perhaps there is a connection between your callback setting the .abort property to null and the later issue with the .abort property being null. You would need to debug that.

comment:6 in reply to:  5 Changed 11 years ago by sabapathy.k@…

Replying to dmethvin:Hello dmethvin,

Thanks much for your assistance. I will remove those lines in my code and check. I will let you know the status.

This is a critical issue in my project, so any help would be much appreciated. Is there a way I can contact the jquery support team, for assistance?.

Thanks & regards, Sabapathy K

comment:8 in reply to:  7 ; Changed 11 years ago by sabapathy.k@…

Replying to scott.gonzalez: Thanks dmethvin and scott for your valid suggestions.

Hi dmethvin, After removing the code lines where it was modifying the object it was not owning, I started getting the following error: "Message: Object doesn't support this property or method Line: 975 Char: 9 Code: 0 URI:"

Which clearly indicated that we are getting close to the problematic part of the code. The error in line 975 is related to Defferred Objects section in the file jquery-1.5.2.

In my code I call the $.ajax (to send the next request), in either "success" callback or in the "error" callback in a specific case. Sometimes in a ajax request cycle (interval of 1.5 sec), I have to send ~3 requests in sequence. My doubt here was, the next request might have been sent before the previous was "complete". Could this be a problem? Can't the "success" or "error" callbacks or the ajax object be queued in jquery?

Now I have changed the implementation: In each request cycle I have implemented a loop, using SetTimeout (async delay) to check whether the previous request is "complete" and if compelete it sends the next request.

I have implemented "beforeSend" and "complete" callback to check the status of the request using a flag say, "ajax-in-progress"(var).

Do you think calling the ajax in chain is a problem? Though it was called only after the event "success" or "error". Can you please clarify.

Thanks a lot!

Best regards, Sabapathy K

comment:9 in reply to:  8 Changed 11 years ago by sabapathy.k@…

Replying to sabapathy.k@…:

Can you please provide me your inputs, regarding my recent comment? That would be of Great Help.

Thank you.

comment:10 Changed 11 years ago by dmethvin

@sabapathy since this does not seem like a bug in jQuery, the conversation isn't appropriate here. Please ask for help on a forum or StackOverflow. If you determine there is a bug, please provide a minimal test case. Your code above seemed to have several problems, but again, the bug tracker is not the appropriate place for debugging user code.

Note: See TracTickets for help on using tickets.