473,666 Members | 2,047 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 20449
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
18468
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 is where a form is printed using : <input type="button" name="Button" value="Print Order" onClick="window.print();"> or when the order form is reset using a JavaScript function :
3
2291
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) { document.getElementById("pippo").value=num+":"+num2+"."+num3; } </SCRIPT> that I call when I download the file:
1
11665
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 : function sjekk(navn) { alert(navn); // or alert(navn) return(false);
5
25845
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 function...if that makes sense. Here's what I mean... I have a javascript array set up like so: <script language="javascript" TYPE="text/JavaScript"> //custom object constructor
4
6313
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 Code: Public Sub VBProcedure() .. ..
18
43539
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. (It's for Google Maps, but I won't bore you with the complexities of that, as it doesn't affect the question). Mochas kudos to anyone able to solve this widdle.
1
1197
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 javascript function on the client side. And I need to send to that javascript function the RowIndex.
5
17313
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 this is the same for function pointers. And if yes, how do you do that ? And how do you assign it to 0 or Null. Here below I have written a small program. I use an array of function pointer. Because the function pointer is located in the main()...
2
1729
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 to "Create" the first data sample, because "clone" uses the last datas in the .xml file, and obviously is not proper if xml file is empty. Here is my code. <script type="text/javascript">
0
8448
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8871
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8640
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2773
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.