Home     |      Learn AJAX     |      Forum     |      Register     |      Submit Resource     |      Submit Article      |      Contact Us

Home Security
 

JSONP and Memory Leaks

 

Data storage in an Ajax or JavaScript based application is a little bit challenging because of the strict enforcement of same-origin policy. This security measure prevent developers from tapping into additional sources of information since some sources are not secured and can be used as a gateway for attacks.


But as long as the developer is assured of the security protocols implemented in another source, developers can still use the application. A popular work-around developers often use for same-origin security is in using JSONP.


It's a small but direct method in extracting data from 3rd party sources. Developers simply create a script that will fetch information from a source. By attaching JSONP in the header, JavaScript will interpret it as one of its reliable sources and proceed to fetch the information to use in the application.


Even though this setting can work well in various browsers, it can lead to serious memory leaks. This is especially true when developers opt to use libraries and frameworks for JavaScript and Ajax based application.
Clogging the Header


When JSONP is created to call on 3rd party data, the scripts can easily clog the headers. This situation can create problems not only in understanding the code for developers but also for the headers ability to execute some functions which will slow down the application.


This problem will force the application to remove the script after it was successfully used. This technique in the application again opens the header for other functions.


The technique of shedding the script is very popular in frameworks and libraries. It's a common feature from this tools since this will help them implement certain functions faster even with heavy customization from developers.


The Memory Leak Side Effect


The technique of shedding the scripts in the header may have freed up some space but the framework didn't "clean" the function enough. That means the scripts were the only ones removed and nothing more.


There is no proper garbage collection in the header as other information and variables are still left in the header. Because the information is left behind the header, it's simply an information without any attached function. Developers will never be to use any function and the information will end up as a memory leak.


Cleaning the Information


There are two ways a developer can deal with this problem. The first step is to develop the application from the ground up. Memory leak with JSONP usually happens when developers opt to use various frameworks and libraries. But this option will actually take a lot of time to implement that storing the information in the application is a better option rather than building the application with a 3rd party source of information.


Another trick developers can use is to implement clearAttributes function before any clearing function in the framework. Just make sure that you'll be using elements that can recognize clear attributes or else the function will not work at all. Memory leaks will most likely happen if the attached functions in JSONP will not work with clearAttributes.



Read Next: Rails Authlogic



 

 

Comments



Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links