Monday, April 20, 2009

Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.

If you are getting this error, this means you are conceptually doing wrong somewhere.Ideally ajax scenarios are meant only for small to medium server side calls not for getting tons of data, and if you are getting a lot of data using the asynchronous request then you are asking for trouble.So in such scenarios it is best to go and implement server side logic.But what if you are at a stage where you can't change your application logic now.

1.So for such a situation there are two ways either implement paging in getting your data which is very simple if you are using jQuery with any other server side technology.

Here is a quick link which tells you how to enable paging and many other things in your custom code.

2.If you can't enable paging also then you are left with only one other solution which is not so good but if your service call is failing then it will prevent the service call from failing, but if you are loading large amount of data again if you prevent your service call from failing still your browser will go abrupt and seems like it has hanged, but if you still want to try then just make this entry in your web.config file to increase the max-request length of the json-request

<jsonSerialization maxJsonLength="2147483644"></jsonSerialization>

Important thing to keep in mind is that the maximum value for the integer field is 2147483647 and this limit has to remain inside the bounds of this value.

Happy Programming!!!

Saturday, April 18, 2009

jQuery Leaking Memory:-Be careful while using in big applications

jQuery is very small and useful javascript library which is a must for every developer related to web. I also have used jQuery in my applications a lot, but recently i found that jQuery is leaking memory which is causing trouble to my applications,so be careful while using your selectors and creating dynamic DOM elements by using jQuery.In this article i will discuss the simple ways to track the memory leak in your application and comments related to optimizing and reducing the memory leaks using jQuery are always welcome.

How to detect the memory leak in your web application

There is a very simple tool available on web known as "Drip" which can help you to test the memory leaks in your web applications

You can download drip from

Documentation of drip is available at

Drip can catch the memory leaks inside the boundary of Internet Explorer but not outside its boundary.

A typical run on one of my applications which is fully jQuery dependent gives me these results.

What Drip does is that it unloads the page and checks for the memory leaks which remained even after the page was unloaded.

Given below is the drip test on

As you can see that also have some memory leak which seems to be a bug to me in jQuery code itself.

On some research on net i found that commenting out few lines of code in the jQuery itself can reduce some of the memory leaks in your application but still the memory leak is there and doesn't leave you, might be in future we get some bug fix on this memory leak thing from the jQuery team.

The lines of code commenting which can do little magic is found inside the jQuery library

if ( div.attachEvent && div.fireEvent ) {
		div.attachEvent("onclick", function(){
			// Cloning a node shouldn't copy over any
			// bound event handlers (IE does this) = false;
			div.detachEvent("onclick", arguments.callee);

If any one of you have some other tips and tricks to reduce this memory leaking and any other way to prevent it.Do post comments to help the community and also help a lot of jQuery developers and jQuery itself to be a bug free library.

Happy Programming!!!