From tedd at sperling.com Tue Sep 1 08:19:22 2009 From: tedd at sperling.com (tedd) Date: Tue, 1 Sep 2009 09:19:22 -0400 Subject: [Javascript] Object reference usage (was Javascript and FF) In-Reply-To: References: <19461870.1251734082017.JavaMail.root@n13> Message-ID: At 11:32 AM -0700 8/31/09, Paul Novitski wrote: >(Those return alerts are purely for logic illustration and aren't >what I do in production code.) Why not? I can see hiding errors from hackers when writing server-side scripts, because you don't want to give them any information that they may of use against your code. But with client-side scripts, the hackers have all the code -- so who cares if they see an error or not? What harm does it do? Additionally, I would rather have a client say "Your code doesn't work -- it report 'Paragraph is empty'" than say ""Your code doesn't work". In addition, the client might even look at the error and think it's their fault and provide a solution themselves (i.e., add a paragraph). Additionally, later when you (or another programmer) review the code alerts provide great documentation. So why not leave in production alerts? Cheers, tedd PS: And thank you for your other postings -- quite informative reading. -- ------- http://sperling.com http://ancientstones.com http://earthstones.com From paul at juniperwebcraft.com Tue Sep 1 15:21:46 2009 From: paul at juniperwebcraft.com (Paul Novitski) Date: Tue, 01 Sep 2009 13:21:46 -0700 Subject: [Javascript] JavaScript error reporting (was: Object reference usage (was Javascript and FF)) In-Reply-To: <10340902.1251811229175.JavaMail.root@n13> References: <19461870.1251734082017.JavaMail.root@n13> <10340902.1251811229175.JavaMail.root@n13> Message-ID: At 9/1/2009 06:19 AM, tedd wrote: >At 11:32 AM -0700 8/31/09, Paul Novitski wrote: >>(Those return alerts are purely for logic illustration and aren't >>what I do in production code.) > >Why not? > >I can see hiding errors from hackers when writing server-side >scripts, because you don't want to give them any information that >they may of use against your code. But with client-side scripts, the >hackers have all the code -- so who cares if they see an error or >not? What harm does it do? > >Additionally, I would rather have a client say "Your code doesn't >work -- it report 'Paragraph is empty'" than say ""Your code doesn't work". > >In addition, the client might even look at the error and think it's >their fault and provide a solution themselves (i.e., add a paragraph). > >Additionally, later when you (or another programmer) review the code >alerts provide great documentation. > >So why not leave in production alerts? Thanks, Tedd; really great topic. I think it helps here to differentiate among at least four audiences for our JavaScript programs -- ourselves during development and deugging, ourselves after launch, our clients the website owners, and website visitors. I don't think it serves good purpose to inform a website visitor of low-level problems. I build pages that work without JavaScript, then add JavaScript as an enhancement. If the user agent that downloads the page doesn't have a JavaScript interpreter running for whatever reason, or if it does but it's too old to understand the DOM, my pages should still work just fine (just perhaps not as responsively or sexily). This means that if my script runs into a situation it can't handle, such as a crucial element not found, it can quit quietly and still leave the user with a functional page. (It's important to test for the presence of critical elements early in a script so it's less likely to fail with a user interface half-rendered.) It would be irritating for visitors to have to click on alerts, a lot of the messages would be next to meaningless, there would be nothing they could do about the errors directly, and they would be left with a negative impression of the site ("It's broken"). Only a few of the grumpiest or geekiest would go out of their way to complain; I think most would simply leave, not come back, and not recommend the site to others. I feel that website visitors should be shielded from a website's dirty laundry; it's our business to provide the client's content agreeably on whatever level of functionality. I rely on temporary alerts among other tools when debugging a stubborn script, but the vast majority of those alerts are for my eyes only and don't belong in the code, at least not uncommented. I can see the purpose of retaining certain low-level error messages for a client who can either fix the problem or let me know there is one, but I would want the messages to be for their eyes only. One way to do this would be to let the client log in so there's a cookie to let JavaScript know it's OK to say Ouch. I've done this server-side and never in JavaScript but it would be easy enough to implement. However I think it's a fair generalization to say that the vast majority of website clients are not technically web savvy and I tend to lump them with website visitors as far as low-level error reporting is concerned. After a website has launched and I've moved on to other projects, I'd rather use XMLHttpRequest to log the error in a database and/or send myself an email to alert myself to internal problems rather than to bother the visitor -- or the client, in most cases -- with runtime alerts. Regards, Paul __________________________ Paul Novitski Juniper Webcraft Ltd. http://juniperwebcraft.com From trojani2000 at hotmail.com Tue Sep 1 17:21:23 2009 From: trojani2000 at hotmail.com (Troy III Ajnej) Date: Tue, 1 Sep 2009 22:21:23 +0000 Subject: [Javascript] Javascript and FF In-Reply-To: <758F7C1467574CA098ADBA712C84F18C@delweglaptop> References: <4B92B2C4E6594671A192A9624CF685D3@delweglaptop> <758F7C1467574CA098ADBA712C84F18C@delweglaptop> Message-ID: Hello Del, > In the past I assumed that the statement in line 189 > function process_form(calculator) > did declare/define calculator. No, in fact it never did! That's an internal local function argument/variable. > I found the same error and am confused. > calculator is the name of the form. So it is a a name/id of a html element you are referring there! Therefore, you were accessing that element directly by id/name. > If that is no longer valid, what is? Where do I find such information? Lots of declarations instructions and values throughout the script are depending on that element. So, missing that element will cause a general failure. Therefore declaring: var calculator = document.getElementById('calculator'); (anywhere in your script) May just bring it all back on gear. Cause there's no other 'true' error there. Regards. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Troy III progressive art enterprise ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > From: del at delweg.com > To: javascript at lists.evolt.org > Date: Sun, 30 Aug 2009 07:46:51 -0500 > Subject: Re: [Javascript] Javascript and FF > > > ----- Original Message ----- > From: "Troy III Ajnej" > > > > > The javascript error is at line 424, > > if (calculator.measurement_units[k].checked == true) > > The report says: "calculator" is not defined. > > > > > > > > I never found any references to "calculator" - what is it? Is it an > > element? > > > Hi Troy; > I found the same error and am confused. > calculator is the name of the form. > In the past I assumed that the statement in line 189 > function process_form(calculator) > did declare/define calculator. > This function is called when the "estimate" button is clicked on the form so > it has been executed before line 424.. > > If that is no longer valid, what is? Where do I find such information? > Thanks. > Del > > > _______________________________________________ > Javascript mailing list > Javascript at lists.evolt.org > http://lists.evolt.org/mailman/listinfo/javascript _________________________________________________________________ With Windows Live, you can organize, edit, and share your photos. http://www.windowslive.com/Desktop/PhotoGallery From tedd at sperling.com Tue Sep 1 17:24:55 2009 From: tedd at sperling.com (tedd) Date: Tue, 1 Sep 2009 18:24:55 -0400 Subject: [Javascript] JavaScript error reporting (was: Object reference usage (was Javascript and FF)) In-Reply-To: References: <19461870.1251734082017.JavaMail.root@n13> <10340902.1251811229175.JavaMail.root@n13> Message-ID: At 1:21 PM -0700 9/1/09, Paul Novitski wrote: >At 9/1/2009 06:19 AM, tedd wrote: > >So why not leave in production alerts? > >I think it helps here to differentiate among at least four audiences >for our JavaScript programs -- ourselves during development and >deugging, ourselves after launch, our clients the website owners, and >website visitors. A good division of audiences, but I have a hard time dividing myself into before and after launch. :-) --------- >I don't think it serves good purpose to inform a website visitor of >low-level problems. I build pages that work without JavaScript, then >add JavaScript as an enhancement. I realize graceful degradation, but that really isn't a part of the "Why not show errors?" question. Alerts require javascript and if javascript isn't there, then the user doesn't see any errors anyway and thus my question is moot. --------- -snip-- > It would be irritating for visitors to have to click >on alerts, a lot of the messages would be next to meaningless, there >would be nothing they could do about the errors directly, and they >would be left with a negative impression of the site ("It's broken"). That depends upon how the errors are presented. As a visitor to a site, I would rather see an explanation as to what went wrong rather than just have something not work right without an explanation. As for users doing something about it, I agree that most users wouldn't normally do anything. But we still ask users to enter data properly, right? I don't really see the difference in asking a user to enter a date correctly (Y/M/D or M/D/Y) or telling them that something went wrong with the date they entered -- if you see what I mean? This more of a human engineering problem. --------- >Only a few of the grumpiest or geekiest would go out of their way to >complain; I think most would simply leave, not come back, and not >recommend the site to others. I don't know -- do you have data to support your conclusion? Let me ask you this, which is better on a car's dashboard, an idiot-light or a gauge? I like gauges. It doesn't mean I can fix the problem, but it gives me more information about what's wrong and makes me feel better. I can speak with authority to the mechanic by saying "This shows low oil pressure" rather than pointing to the idiot light that reads "Engine Needs Service Soon." I hate that light. --------- >I feel that website visitors should be >shielded from a website's dirty laundry; it's our business to provide >the client's content agreeably on whatever level of functionality. Again, I don't know. However, I do think that most of the "dirty laundry" can be sanitized for the viewing public. I also believe that if you inform your visitors as to what's happening (i.e., site is temporary closed for repairs) it's better than not (i.e., viewer sees a blank page). --------- >I think it's a fair generalization to say that the vast majority of >website clients are not technically web savvy and I tend to lump them >with website visitors as far as low-level error reporting is concerned. It's also a fair generalization to say that the vast majority of clients have problems with spelling and grammar, but I tend to inform them when they make a mistake. So why not let me know when I make a mistake? I have clients who inform me when they see something wrong and the sooner the better, am I right or am I right? Nothing is worse than the "Emperor's new clothes" syndrome. --------- >After a website has launched and I've moved on to other projects, I'd >rather use XMLHttpRequest to log the error in a database and/or send >myself an email to alert myself to internal problems rather than to >bother the visitor -- or the client, in most cases -- with runtime alerts. That's a good idea -- namely, to have a system in place that lets you know when something goes wrong. I would like to know how to do that -- I'll look into it. Because without knowing there's a problem, you can't fix it. And without alerts (or what you suggest) you'll never know there's a problem because no one will see the alerts and report the errors, which is/was my point. Plus, we haven't discussed the documentation side of this. In php, due to security concerns I usually have one session variable that controls all error reporting. During development it's turned on and afterwards for production it's turned off. However, all of the alerts are still there for future programmers to review. To me, it's just another part of the documentation. The only difference between php and javascript is where the script resides and who can see it. Considering that javascript provides no security from prying eyes, then security concerns cannot be an issue -- not that you said otherwise. So, the only real difference we have here is IF the users (including the client) can see any errors generated. Of course, this is only a theoretical discussion because we never release scripts that have errors anyway, right? :-) But the discussion here is to the concept of including users' and clients' experiences as ways to improve the code rather than trying to hide errors from them. I am not suggesting using users and clients as beta-testers (like M$ does), but simply including them as part of the continuing process to improve the code. Now what do you think? Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com From lester at denhaag.org Tue Sep 1 18:26:26 2009 From: lester at denhaag.org (J. Lester Novros II) Date: Wed, 02 Sep 2009 01:26:26 +0200 Subject: [Javascript] JavaScript error reporting In-Reply-To: References: <19461870.1251734082017.JavaMail.root@n13> <10340902.1251811229175.JavaMail.root@n13> Message-ID: <4A9DADA2.3010205@denhaag.org> Paul Novitski wrote: > can see the purpose of retaining certain low-level error messages for > a client who can either fix the problem or let me know there is one, > but I would want the messages to be for their eyes only. One way to How about if (window.opera) opera.postError(msg); else if (typeof console != 'undefined' && console) console.log(msg); This works unobstrusively in Opera, Safari and Firefox with Firebug installed. Also, there's Firefox's 'dump()' command [so one wouldn't need Firebug] but so far I haven't been able to get that to work. My 0.02 Eur. l8R lES -- Microsoft's business practices have fundamentally diminished (in fact, came very close to eliminating) competition, choice and innovation in how people access the Internet. Mitchell Baker - Mozilla Chair http://lester.demon.nl/superm/ From del at delweg.com Tue Sep 1 20:06:53 2009 From: del at delweg.com (Del Wegener) Date: Tue, 1 Sep 2009 20:06:53 -0500 Subject: [Javascript] Javascript and FF References: <4B92B2C4E6594671A192A9624CF685D3@delweglaptop> <758F7C1467574CA098ADBA712C84F18C@delweglaptop> Message-ID: <1B10BD68ECCE44069EFD946670A0B89D@delweglaptop> > > Hello Del, > > >> In the past I assumed that the statement in line 189 >> function process_form(calculator) >> did declare/define calculator. > > > No, in fact it never did! > > That's an internal local function argument/variable. > > > >> I found the same error and am confused. >> calculator is the name of the form. > > > So it is a a name/id of a html element you are referring there! > > Therefore, you were accessing that element directly by id/name. > > > >> If that is no longer valid, what is? Where do I find such information? > > > Lots of declarations instructions and values throughout the script > > are depending on that element. So, missing that element will cause > > a general failure. > > > > Therefore declaring: > > var calculator = document.getElementById('calculator'); > > (anywhere in your script) > > May just bring it all back on gear. Cause there's no other 'true' error > > there. Try: Understood and appreciated. Del From and-babble at doxdesk.com Wed Sep 2 16:28:39 2009 From: and-babble at doxdesk.com (And Clover) Date: Wed, 02 Sep 2009 23:28:39 +0200 Subject: [Javascript] Object reference usage (was Javascript and FF) In-Reply-To: <59bedf280908310702p44379a32lf8c37ab4946886e6@mail.gmail.com> References: <59bedf280908310702p44379a32lf8c37ab4946886e6@mail.gmail.com> Message-ID: <4A9EE387.5040007@doxdesk.com> Mike Dougherty wrote: > Does it cost anything* to make the variable reference for a single > property assignment? Yes, but it is a minuscule amount. > Does it cost anything* to use the unwieldy but very explicit reference > from root for several assignments? Yes. More lookups means slower in current JS implementations. However it's still a very tiny amount, and a future clever implementation might optimise it away. So do what you find easiest to read and maintain, because the CPU time you're saving by this kind of optimisation is nugatory. It is almost always a 'premature optimisation'. With JS engines being updated and changed all the time, your fancy micro-optimisation for the last generation of JS terps might actually be slower on the new. In the context of the original thread, the shorter form: calculator.measurement_units[k] might actually - where it works at least - perform (unnoticeably) better than the 'proper' form crafted to avoid name clashes: document.forms.calculator.elements.measurement_units[k] (although really of course we should probably just go straight for getElementById today instead of continuing to mess around with the DOM Level 0 form scripting interfaces.) -- And Clover mailto:and at doxdesk.com http://www.doxdesk.com/ From akuhl at telkomsa.net Fri Sep 4 02:41:33 2009 From: akuhl at telkomsa.net (Arno Kuhl) Date: Fri, 4 Sep 2009 09:41:33 +0200 Subject: [Javascript] Allow select on disabled field Message-ID: <2F758E60AA404D5BAFFE50143AD5E8FB@point01> I'm trying to do copy-to-clipboard in javascript. It works fine in IE but FF needs to have preferences changed by the user to allow it, so another option I'm looking at is to just select/mark the data in FF and allow the user to manually copy to clipboard. So the code detects the browser and displays a Copy button in IE and a Mark button in FF. The data is often longer than the display length of the text field, I don't want to use a textarea (though I will if it solves the problem) and don't want to allow user to change the displayed data so I set the field to disabled='true'. In IE I can select the data (with mouse or js) and copy manually (though my js function can already do that anyway) but in FF I can't select the data, and the code for FF document.urllink.focus(); document.urllink.select(); fails on the focus() line because FF won't allow focus on a disabled field. Is there a way I can select data in an input field in FF (ready to be copied to clipboard) but still disable edit? Cheers Arno From msd005 at gmail.com Fri Sep 4 08:06:29 2009 From: msd005 at gmail.com (Mike Dougherty) Date: Fri, 4 Sep 2009 08:06:29 -0500 Subject: [Javascript] Allow select on disabled field In-Reply-To: <2F758E60AA404D5BAFFE50143AD5E8FB@point01> References: <2F758E60AA404D5BAFFE50143AD5E8FB@point01> Message-ID: <59bedf280909040606i745adf2td87710b1046e9e50@mail.gmail.com> On Fri, Sep 4, 2009 at 2:41 AM, Arno Kuhl wrote: > Is there a way I can select data in an input field in FF (ready to be copied > to clipboard) but still disable edit? make the field readonly? You'll be able to select it, but not edit. I vaguely recall that readonly fields are not send with the form controls to the server upon submission. From hucklesby at gmail.com Fri Sep 4 13:05:40 2009 From: hucklesby at gmail.com (David Hucklesby) Date: Fri, 04 Sep 2009 11:05:40 -0700 Subject: [Javascript] Allow select on disabled field In-Reply-To: <2F758E60AA404D5BAFFE50143AD5E8FB@point01> References: <2F758E60AA404D5BAFFE50143AD5E8FB@point01> Message-ID: <4AA156F4.9050902@gmail.com> Arno Kuhl wrote: > I'm trying to do copy-to-clipboard in javascript. [...] There's this: http://code.google.com/p/zeroclipboard/ Cordially, David -- From akuhl at telkomsa.net Mon Sep 7 01:24:01 2009 From: akuhl at telkomsa.net (Arno Kuhl) Date: Mon, 7 Sep 2009 08:24:01 +0200 Subject: [Javascript] Allow select on disabled field In-Reply-To: <59bedf280909040606i745adf2td87710b1046e9e50@mail.gmail.com> References: <2F758E60AA404D5BAFFE50143AD5E8FB@point01> <59bedf280909040606i745adf2td87710b1046e9e50@mail.gmail.com> Message-ID: -----Original Message----- From: javascript-bounces at lists.evolt.org [mailto:javascript-bounces at lists.evolt.org] On Behalf Of Mike Dougherty Sent: 04 September 2009 03:06 PM To: JavaScript List Subject: Re: [Javascript] Allow select on disabled field On Fri, Sep 4, 2009 at 2:41 AM, Arno Kuhl wrote: > Is there a way I can select data in an input field in FF (ready to be > copied to clipboard) but still disable edit? make the field readonly? You'll be able to select it, but not edit. I vaguely recall that readonly fields are not send with the form controls to the server upon submission. _______________________________________________ Thanks Mike, that's exactly what I was looking for. I knew I'd done this before but couldn't for the life of me remember how. Cheers Arno From akuhl at telkomsa.net Mon Sep 7 01:28:36 2009 From: akuhl at telkomsa.net (Arno Kuhl) Date: Mon, 7 Sep 2009 08:28:36 +0200 Subject: [Javascript] Allow select on disabled field In-Reply-To: <4AA156F4.9050902@gmail.com> References: <2F758E60AA404D5BAFFE50143AD5E8FB@point01> <4AA156F4.9050902@gmail.com> Message-ID: <5667DBA3D0354747B0E52B3743044CF5@point01> There's this: http://code.google.com/p/zeroclipboard/ Cordially, David -- Thanks David, I came across Zero Clipboard last week when I was researching the copy-to-clipboard and was put off a bit by the Flash requirement, but I might go that route in the long run because the app is for administrators only so I can probably legitimately set Flash as a requirement for them. Cheers Arno From prashant.er at gmail.com Wed Sep 23 01:46:59 2009 From: prashant.er at gmail.com (Prashant Dahiya) Date: Wed, 23 Sep 2009 12:16:59 +0530 Subject: [Javascript] Garbage Collection/ Freeing-up memory in Java script Message-ID: <1d274390909222346o6a031a49jba4a880eef647380@mail.gmail.com> Hi, I?m trying with this type of code (example): function Hashtable() { this.valueList = new Array(); var somePrivateMethod = function() { return 1; } this.putValue = function(name, value) { this.valueList[name] = value; } } for (var i = 0; i < 100000; i++) { var hash = new Hashtable(); hash.putValue("Key" + i, "Value" + i); delete hash; hash = null; } Running this script , it constantly increases the memory usage. Although the object "hash" is deleted in each iteration and although it is set to null, it does not seem to be removed from memory. Calling $.summary() after execution has finished shows more than 100000 functions still in memory. Running the script a second time increases the memory again. More than 200000 functions are in memory after the second execution. Am I doing anything wrong here ? Any ideas, how I can get rid of the unreferenced memory? In fact, AFAIK JS engines do garbage collection automatically, any idea why does the java script engine does not release the memory immediately although it is unreferenced? Is there a possibility to run the garbage collection of the java script engine ($.gc doesn?t helped much)? Regards, P From andrewsyip at gmail.com Wed Sep 23 03:08:33 2009 From: andrewsyip at gmail.com (Andrew Ip) Date: Wed, 23 Sep 2009 01:08:33 -0700 Subject: [Javascript] Garbage Collection/ Freeing-up memory in Java script In-Reply-To: <1d274390909222346o6a031a49jba4a880eef647380@mail.gmail.com> References: <1d274390909222346o6a031a49jba4a880eef647380@mail.gmail.com> Message-ID: <3F413138-AF6D-4199-BEFA-5EAB854E27B3@alumni.cs.ubc.ca> Hey Prashant, It seems like you're orphaning all the values that were put into your "valueList" array when you delete the reference to the "hash" object. Note that the delete operator in JavaScript basically just sets a variable's value to uninitialized. Try emptying out the valueList array first, then delete the empty valueList array, and finally deleting the "hash" object afterwards. You should see a difference. On another note, I'm not sure what you're trying to do with your Hashtable class, but JavaScript already allows you to use objects as associative arrays. Check out the following: http://www.quirksmode.org/js/associative.html -andrew On 2009-09-22, at 11:46 PM, Prashant Dahiya wrote: > Hi, > > > > I?m trying with this type of code (example): > > > > function Hashtable() { > > > > this.valueList = new Array(); > > > > var somePrivateMethod = function() { return 1; } > > > > this.putValue = function(name, value) { > > > > this.valueList[name] = value; > > > > } > > > > } > > > > > > > > for (var i = 0; i < 100000; i++) > > > > { > > > > var hash = new Hashtable(); > > > > hash.putValue("Key" + i, "Value" + i); > > > > delete hash; > > > > hash = null; > > > > } > > > > Running this script , it constantly increases the memory usage. > Although the > object "hash" is deleted in each iteration and although it is set to > null, > it does not seem to > > be removed from memory. Calling $.summary() after execution has > finished > shows more than 100000 functions still in memory. Running the script a > second time increases the memory again. More than 200000 functions > are in > memory after the second execution. > > > > Am I doing anything wrong here ? > > > > Any ideas, how I can get rid of the unreferenced memory? In fact, > AFAIK JS > engines do garbage collection automatically, any idea why does the > java > script engine does not release the memory immediately although it is > unreferenced? > > Is there a possibility to run the garbage collection of the java > script > engine ($.gc doesn?t helped much)? > > > > Regards, > > P > _______________________________________________ > Javascript mailing list > Javascript at lists.evolt.org > http://lists.evolt.org/mailman/listinfo/javascript From prashant.er at gmail.com Wed Sep 23 03:24:46 2009 From: prashant.er at gmail.com (Prashant Dahiya) Date: Wed, 23 Sep 2009 13:54:46 +0530 Subject: [Javascript] Garbage Collection/ Freeing-up memory in Java script In-Reply-To: <3F413138-AF6D-4199-BEFA-5EAB854E27B3@alumni.cs.ubc.ca> References: <1d274390909222346o6a031a49jba4a880eef647380@mail.gmail.com> <3F413138-AF6D-4199-BEFA-5EAB854E27B3@alumni.cs.ubc.ca> Message-ID: <1d274390909230124r4a24bf5er1c49f961f56859e2@mail.gmail.com> Hi Andrew, Thanks for the reply... I'll try your suggestions. Regards, P On Wed, Sep 23, 2009 at 1:38 PM, Andrew Ip wrote: > Hey Prashant, > > It seems like you're orphaning all the values that were put into your > "valueList" array when you delete the reference to the "hash" object. > Note that the delete operator in JavaScript basically just sets a > variable's value to uninitialized. Try emptying out the valueList > array first, then delete the empty valueList array, and finally > deleting the "hash" object afterwards. You should see a difference. > > On another note, I'm not sure what you're trying to do with your > Hashtable class, but JavaScript already allows you to use objects as > associative arrays. Check out the following: > > http://www.quirksmode.org/js/associative.html > > -andrew > > On 2009-09-22, at 11:46 PM, Prashant Dahiya wrote: > > > Hi, > > > > > > > > I?m trying with this type of code (example): > > > > > > > > function Hashtable() { > > > > > > > > this.valueList = new Array(); > > > > > > > > var somePrivateMethod = function() { return 1; } > > > > > > > > this.putValue = function(name, value) { > > > > > > > > this.valueList[name] = value; > > > > > > > > } > > > > > > > > } > > > > > > > > > > > > > > > > for (var i = 0; i < 100000; i++) > > > > > > > > { > > > > > > > > var hash = new Hashtable(); > > > > > > > > hash.putValue("Key" + i, "Value" + i); > > > > > > > > delete hash; > > > > > > > > hash = null; > > > > > > > > } > > > > > > > > Running this script , it constantly increases the memory usage. > > Although the > > object "hash" is deleted in each iteration and although it is set to > > null, > > it does not seem to > > > > be removed from memory. Calling $.summary() after execution has > > finished > > shows more than 100000 functions still in memory. Running the script a > > second time increases the memory again. More than 200000 functions > > are in > > memory after the second execution. > > > > > > > > Am I doing anything wrong here ? > > > > > > > > Any ideas, how I can get rid of the unreferenced memory? In fact, > > AFAIK JS > > engines do garbage collection automatically, any idea why does the > > java > > script engine does not release the memory immediately although it is > > unreferenced? > > > > Is there a possibility to run the garbage collection of the java > > script > > engine ($.gc doesn?t helped much)? > > > > > > > > Regards, > > > > P > > _______________________________________________ > > Javascript mailing list > > Javascript at lists.evolt.org > > http://lists.evolt.org/mailman/listinfo/javascript > > _______________________________________________ > Javascript mailing list > Javascript at lists.evolt.org > http://lists.evolt.org/mailman/listinfo/javascript > -- Thanks, Prashant Dahiya From trojani2000 at hotmail.com Wed Sep 23 21:01:58 2009 From: trojani2000 at hotmail.com (Troy III Ajnej) Date: Thu, 24 Sep 2009 02:01:58 +0000 Subject: [Javascript] Garbage Collection/ Freeing-up memory in Java script In-Reply-To: <1d274390909222346o6a031a49jba4a880eef647380@mail.gmail.com> References: <1d274390909222346o6a031a49jba4a880eef647380@mail.gmail.com> Message-ID: Hello Dashant There is an online resource that can answer your question and clear up your suspicions on this matter. (instead or interpreting) I will quote it here: [quote start] Instead of requiring manual deallocation, JavaScript relies on a technique called garbage collection. The JavaScript interpreter is able to detect when an object will never again be used by the program. When it determines that an object is unreachable (i.e., there is no longer any way to refer to it using the variables in the program), it knows that the object is no longer needed and its memory can be reclaimed. Consider the following lines of code, for example: var s = "hello"; // Allocate memory for a string var u = s.toUpperCase( ); // Create a new string s = u; // Overwrite reference to original string After this code runs, the original string "hello" is no longer reachable -- there are no references to it in any variables in the program. The system detects this fact and frees up its storage space for reuse. Garbage collection is automatic and is invisible to the programmer. You can create all the garbage objects you want, and the system will clean up after you! You need to know only enough about garbage collection to trust that it works; you don't have to wonder about where all the old objects go. For those who aren't satisfied, however, Section 11.3, contains further details on the JavaScript garbage-collection process. [quote end] Meaning that instead of writing something like: var hash = new Hashtable(); hash.putValue("Key" + i, "Value" + i); delete hash; hash = null; You could simply declare: Hashtable = new Hashtable() [the following code] And the previous Hashtable will be automaticaly deleted by js garbage collector in its first turn. Regards ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Troy III progressive art enterprise ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > Date: Wed, 23 Sep 2009 12:16:59 +0530 > From: prashant.er at gmail.com > To: javascript at lists.evolt.org > Subject: [Javascript] Garbage Collection/ Freeing-up memory in Java script > > Hi, > > > > I?m trying with this type of code (example): > > > > function Hashtable() { > > > > this.valueList = new Array(); > > > > var somePrivateMethod = function() { return 1; } > > > > this.putValue = function(name, value) { > > > > this.valueList[name] = value; > > > > } > > > > } > > > > > > > > for (var i = 0; i < 100000; i++) > > > > { > > > > var hash = new Hashtable(); > > > > hash.putValue("Key" + i, "Value" + i); > > > > delete hash; > > > > hash = null; > > > > } > > > > Running this script , it constantly increases the memory usage. Although the > object "hash" is deleted in each iteration and although it is set to null, > it does not seem to > > be removed from memory. Calling $.summary() after execution has finished > shows more than 100000 functions still in memory. Running the script a > second time increases the memory again. More than 200000 functions are in > memory after the second execution. > > > > Am I doing anything wrong here ? > > > > Any ideas, how I can get rid of the unreferenced memory? In fact, AFAIK JS > engines do garbage collection automatically, any idea why does the java > script engine does not release the memory immediately although it is > unreferenced? > > Is there a possibility to run the garbage collection of the java script > engine ($.gc doesn?t helped much)? > > > > Regards, > > P > _______________________________________________ > Javascript mailing list > Javascript at lists.evolt.org > http://lists.evolt.org/mailman/listinfo/javascript _________________________________________________________________ Bing? brings you maps, menus, and reviews organized in one place. Try it now. http://www.bing.com/search?q=restaurants&form=MLOGEN&publ=WLHMTAG&crea=TEXT_MLOGEN_Core_tagline_local_1x1 From riegel at clearimageonline.com Mon Sep 28 13:23:51 2009 From: riegel at clearimageonline.com (Terry Riegel) Date: Mon, 28 Sep 2009 14:23:51 -0400 Subject: [Javascript] That pesky closure thing :( Message-ID: <21840F9C-E91A-4F1B-8235-A0369B03570A@clearimageonline.com> Hello Everyone, I have a new project I am working on and I think the word closure will come up in the solution. Something I have not been able to get my head around. I have this function function ajaxForms(c) { var forms= document.getElementsByTagName('form'); for (i=0; i References: <21840F9C-E91A-4F1B-8235-A0369B03570A@clearimageonline.com> Message-ID: You should be able to just call: processing(forms[i]) since the anonymous function you're assigning to your Ajax onLoading variable is able to see the variables that's bound within the body of the ajaxForms function. And yes, this is because a closure is formed. :) -andrew On Mon, Sep 28, 2009 at 11:23 AM, Terry Riegel wrote: > Hello Everyone, > > I have a new project I am working on and I think the word closure will > come up in the solution. Something I have not been able to get my head > around. > > I have this function > > ?function ajaxForms(c) { > ?var forms= document.getElementsByTagName('form'); > ?for (i=0; i ?{ > ? if (forms[i].className.indexOf(c) != -1) > ? { > ? ?forms[i].onsubmit=function () > ? ?{ > ? ? new Ajax.Request( > ? ? ? this.action, > ? ? ? { > ? ? ? ?method: this.method, > ? ? ? ?parameters: 'ajaxrequest=TRUE&'+riegelSerialize(this), > ? ? ? ?encoding: 'UTF-8', > ? ? ? ?onLoading: function (){if(typeof processing == "function") > {processing(this)} ? } > ? ? ? } > ? ? ? ?); > ? ? return false; > ? ?} > ? } > ?} > } > > I want to take that onLoading line and have it run a function called > processing. The problem I am having is I want to pass "this" to the > processing function. I want this to be the form object forms[i]. > > Any ideas on how I can accomplish this. > > Thanks, > > Terry Riegel > _______________________________________________ > Javascript mailing list > Javascript at lists.evolt.org > http://lists.evolt.org/mailman/listinfo/javascript >