JQUERY.AJAX ($.AJAX) AND ITS MEMORY LEAKING (Bug reported)

I reported a bug in http://bugs.jquery.com/ticket/10824

Anúncios

jQuery.ajax ($.ajax) and its memory leaking (BUG) – How to solve it?

Hi everyone, today I faced a serius problem with an application suffering of memory leaking. After almost get crazy I could isolate the problem and I figured out the problem was the jQuery.ajax.

All my pain I posted in here (http://stackoverflow.com/questions/8158739/ie-memory-leak-and-eval-with-jquery/8176724#8176724) but I didn’t receive any answer, hopefully I could manage that by myself.

Summarizing, if you will use in your application jQuery.ajax, which will be called in a regular basis (like every 10 seconds) I’d recommend you to make the call as below:

var request = $.ajax({ .... });

It will create a reference of that request to the declared variable (request).

When finished the request, YOU must do by yourself this:

 request.onreadystatechange = null;  
 request.abort = null;  
 request = null;

jQuery.ajax doesn’t do that and the memory never releases. 

Let me know if it was useful for you.

jQuery Selector tip – two classes or :not a class?

Haha, what a confusing tittle, isn’t it.

Ok, tip of the day.

How to select an element with jQuery by two classes?
$(‘.class1.class2’)

But, how to select an element with jQuery with a class1 but without  class2?
$(‘.class1:not(.class2)’)

It’s sometimes is quite trick to figure out but is really straightforward.

Dica: jQuery + Ajax + ASP.NET Generic Handler = Interactividade e Performance

Hoje achei um post interessante no link abaixo falando sobre a integração do jQuery, Ajax e .Net… e ainda tem um exemplo muito bom!

http://blastersystems.com/blog/2010/08/jquery-ajax-asp-net-generic-handler-interactividade-e-performance/

Dica para quem quer usar o retorno JSON:

//método adicionar cliente
$(‘#btnAdicionar’).click(function () {

$.ajax({
url: ‘../../Handlers/AdicionarClienteHandler.ashx’,
data: $(‘form’).serialize(),
type: ‘POST’,
success: function (data) {

alert(‘Cliente adicionado com sucesso.’);

var html = ‘

‘;
html+= ” + data[0] + ”;
html+=’Username: ‘ + data[1] + ‘‘;
html+=’Email: ‘ + data[2] + ‘‘;
html+=’Telefone: ‘ + data[3] +’‘;
html+=’Telemóvel: ‘ + data[4] + ‘‘;
html+=’Fax: ‘ + data[5] + ‘‘;
html+=’ 

‘;

$(‘#listClientes’).append(html);
},
error: function (data) {
alert(“Ocorreu um erro ao processar o seu pedido.”);
}
});
});