473,385 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Delete Javascript function

Hi

I'm creating now a site which is using heavly AJAX and what comes with
it, many Javascript functions are used. However many of these functions
are used only once (mainly to load new content by sending request to
server and by using DOM editing site content based on the response). So
keeping these functions in memory, while new content with new functions
is loaded, would be just wasting of memory.

And here goes my question - is there any way to delete Javascript
functions or free memory used by them? I've tried with "delete"
operator but it doesn't work with functions. I thinked also about
setting the function name to "null", but I'm not sure if Javascript
will automaticlly free memory.

Thanks for any advices.

Aug 8 '06 #1
2 20438
Try using variables to create your functions maybe???

var a = function() { blargh }
a();
a = 0;

Aug 8 '06 #2

la***@o2.pl wrote:
Hi

I'm creating now a site which is using heavly AJAX and what comes with
it, many Javascript functions are used. However many of these functions
are used only once (mainly to load new content by sending request to
server and by using DOM editing site content based on the response). So
keeping these functions in memory, while new content with new functions
is loaded, would be just wasting of memory.

And here goes my question - is there any way to delete Javascript
functions or free memory used by them? I've tried with "delete"
operator but it doesn't work with functions. I thinked also about
setting the function name to "null", but I'm not sure if Javascript
will automaticlly free memory.
You can do it by changing the reference to any value, it might as well
be null unless you feel 'undefined' is better. e.g.

function foo () { ... }
Creates a property of the global object with a value that is a
reference to the function object 'foo'.

window.foo = 'blah';
Replaces the value of window.foo with the primitive string 'blah'.
There are no more references to the function object foo, so it can be
collected.

Removing all references to an object (or leaving only circular
references between objects) should make it available, however you don't
have any control over when it runs[1] and it may not run until the page
is unloaded.

There is a useul thread here (take note of Richard's stuff only):

<URL:
http://groups.google.com/group/comp....444fd554f6d112
>

1. Some browsers allow you to expressly call garbage collection, but
not many (only IE that I know of).
--
Rob

Aug 8 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Pete | last post by:
I have a site which is using sessions to pass data from one page through to the next. The problem that I have is that there are only two places where the session could/should be destroyed. This...
3
by: Cristian | last post by:
Hi all, When I download a file with ftp_nb_get, I'd like to show the elapsed time and so I had insert this javascript function in my php page <SCRIPT> function scrivi(num, num2, num3) {...
1
by: Obscurr | last post by:
i've got an array created in php that I want to send over to a javascript function. onclick = "return sjekk(<?echo $names; ?> )" in my "sjekk" function, when I try to print an alert : ...
5
by: elsenraat_76 | last post by:
Hello! I was wondering if someone could help me out with a problem I'm having? I'm trying to input a javascript value into an anchor tag (from a function), but don't have an event to call the...
4
by: Martin Feuersteiner | last post by:
Dear Group I'm using VB to write an aspnet application. I would like to call a javascript function from within a VB Sub or VB Function, is it possible? My code is something like this: VB...
18
by: Chris Ianson | last post by:
Hi geniuses (or is that genii, or genies) The challenge is as above really. I have a page with an iframe in it, and need to call a JS function in the *parent* page, *from* inside the iframe. ...
1
by: Miguel Dias Moura | last post by:
Hello, In an Asp.Net 2.0 GridView I have ButtonField for deleting the record. I used .CommandName = "Delete". I want to cancel this server side action. I want, instead, the button to call a...
5
by: wongjoekmeu | last post by:
Hiya all, I am trying to use function pointers. I know that usually if you use a pointer to an object, you have to release the memory at the end by calling the delete keyword. I was wondering if...
2
by: driveman | last post by:
Hello, I have existing code working perfectly, which can : -clone existing datas (title, textarea, link-to-picture) contained in xml file, and : -delete datas. I looking for a javascript code...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.