Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > can't release memory

Reply
Thread Tools

can't release memory

 
 
tal.shemesh@gmail.com
Guest
Posts: n/a
 
      02-04-2008
Hi,
Recently i started to work with javascript and notice that i have
a lot of memory leaks.
I built simple example which creates 100,000 strings and then i
delete them and
the memory is still there

any idea what should i do?


code:
var X = [];
var y;
debugger;
for (y = 0 ; y < 100000 ; y++){
X[y] = "fdsfsddfsdfsdfsdfsdfdsfdsfsdfsdf";
}
debugger;
X = null;
delete X;
 
Reply With Quote
 
 
 
 
Amrit Ranjan
Guest
Posts: n/a
 
      02-04-2008
On Feb 4, 9:14 pm, tal.shem...@gmail.com wrote:
> Hi,
> Recently i started to work with javascript and notice that i have
> a lot of memory leaks.
> I built simple example which creates 100,000 strings and then i
> delete them and
> the memory is still there
>
> any idea what should i do?
>
> code:
> var X = [];
> var y;
> debugger;
> for (y = 0 ; y < 100000 ; y++){
> X[y] = "fdsfsddfsdfsdfsdfsdfdsfdsfsdfsdf";
> }
> debugger;
> X = null;
> delete X;


delete key word is not applicable for those variable which are
declared with var keyword. Please refer following site.
http://developer.mozilla.org/en/docs...elete_Operator
If you really want to clear the memory use Array.splice method
example
X.splice(0, X.length);
this method will clear the memory of the X, but X is still an array.
Now make X = null.
Do not assign X = [] again. It will just change the reference
pointer. any way as because var is used and the execution sample is in
function, it will clear the memory when scope goes out.

Thanks,
Amrit Ranjan
 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      02-04-2008
Amrit Ranjan wrote:
> delete key word is not applicable for those variable which are
> declared with var keyword. Please refer following site.
> http://developer.mozilla.org/en/docs...elete_Operator


`delete' is applicable in that case, but it does not change anything.

> If you really want to clear the memory use Array.splice method
> example
> X.splice(0, X.length);
> this method will clear the memory of the X,


Certainly it won't. The memory assigned to the values of the elements of
the array *may* be freed but it could also be that the corresponding objects
are merely marked for garbage collection.

> but X is still an array.


Which is why the memory required for storing that object is only reduced, if
that.

> Now make X = null.


That assignedment could have been performed in the first place and it would
have made little difference. That is, with that assignment X is marked as
being ready for garbage collection, and the objects its properties refer to
as well, provided there are no further references to either object.

> Do not assign X = [] again. It will just change the reference
> pointer.


There is no significant difference in assigning [] and calling
X.splice(0, X.length). See ECMAScript Ed. 3, section 15.4.4.12.

> any way as because var is used and the execution sample is in
> function, it will clear the memory when scope goes out.


It *may* clear the memory then.

I really wonder where your "wisdom" comes from.


PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      02-04-2008
Thomas 'PointedEars' Lahn wrote:
> Amrit Ranjan wrote:
>> Now make X = null.

>
> That [assignment] could have been performed in the first place and it
> would have made little difference. That is, with that assignment X is
> marked as being ready for garbage collection, [...]


Correction: the object X refers to is marked so as well as

> [...] the objects its properties refer to [...], provided there are no
> further references to either object.



PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert "quick" release to "slow" release tripod head plate Mike Digital Photography 0 05-17-2009 11:01 AM
Adding quick-release to a non-quick-release tripod head ste7esmith@hotmail.com Digital Photography 4 11-20-2006 03:19 PM
J2ME: javac: target release 1.1. conflicts with default source release 1.5 John Goche Java 1 12-17-2005 08:12 PM
NEWS RELEASE: Leone's "Nobody" Films 1st time mastered in HD for DVD release with 240 Minutes Extras Torsten Kaiser \(TLEFilms\) DVD Video 1 06-06-2005 03:17 PM
GC does not release memory...memory keeps growing!!! Mahesh Prasad ASP .Net 1 02-22-2004 08:40 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57