I want help from all you wonderful guys. I want to know how can we free memory occupied by an Array. That means all the elements associated with this array should be deleted.
i dont think he is looking for such a processor consuming way of deleting the memory. i think delete keyword works better for his needs. or basically setting the array to null.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title>www.daniweb.com</title>
<script type="text/javascript">
<!--
window.onload = function() {
var bigArray = [];
bigArray2 = [];
for ( var i = 0; i < 500; i++ ) { // creating 500 items into bigArray >>>
bigArray[ i ] = "Item" + i;
bigArray2[ i ] = "Item" + i;
}
/*
You can use the delete operator to delete variables declared implicitly but not those declared with the var statement.
Output Sample: */
delete bigArray; // ignore's the delete process.
alert( bigArray.length ); // outputs the same length
// either one of the following statement will work, if you have defined it using the var statement.
bigArray = null; // or:
// bigArray = []; // reset's all items...
delete bigArray2; // this one works and delete's the bigArray2 variable.
};
// -->
</script>
</head>
<body>
<div></div>
</body>
</html>
both ways will provide the same results, the only difference between the two procedure, is that when you use the delete operator, your variable will no longer be accessible within the function unless you redefined it.
Hope we've claimed your needs...
@serkan - welcome , you had a better solution compared to my first post.
wow i have created big javascript applications so far and yet i have never needed to delete something from memory. why do you need it?
We usually encounter this problem when working with embedded devices (settop boxes etc.) where there is very less memory. We need to free memory where ever its possible.
Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.
This thread is more than three months old
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.