SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: Loosing the memory error
-
Nov 18, 2002, 06:30 #1
- Join Date
- Feb 2002
- Location
- Gatwick, UK
- Posts
- 1,206
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Loosing the memory error
I was just playing with something ... and I hit a problem.
I wrote a quick spew system for a color table.
The Javascript is a bit complex for beginners, in my normal fashion, but you'll get the idea ( notice that stabArr is iterative, and calls back down a stack list - like an object handle in c++ ):
[VBS]
<script language="Javascript">
<!--
var hex = new Array('00','33','66','99','CC','FF');
var T = document.createElement('TABLE');
document.body.appendChild(T);
var Tr = T.insertRow(0);
var sC = new Array(0,0,0);
var pD = false;
function addCell(){
var Td = Tr.insertCell(Tr.cells.length);
with (Td.style){
backgroundColor = '#'+hex[sC[0]]+hex[sC[1]]+hex[sC[2]];
width = '10px';
height = '10px';
fontSize = '1px';
}
Td.innerHTML=' ';
if (stabArr()){
addCell();
}
else {
alert('finished');
}
}
function stabArr(v){
var r;
if (!arguments.length) v = 2;
if (v<0) r = 0;
else r = 1;
sC[v] += 1;
if (sC[v] == hex.length){
sC[v] = 0;
Tr = T.insertRow(T.rows.length);
r = stabArr(v-1);
}
return r;
}
addCell();
//-->
</script>
[/VBS]
Now the problem is - when you scale the array up ( or call that array on a slow machine ) to:
('00','11','22','33','44','55','66','77','88','99','AA','BB','CC','DD','EE','FF')
You'll see you get an "out of memory" error.
I thought this might be to do with buffering the table - so I moved it to the top, as you see - that didn't work.
Instead I stopped using dynamic methods, and document.wrote the table, trs and tds... still a memory issue....
Please DON'T go assuming I want a script similar to what
I'm doing - I don't - I just want to see how to get this one
to work... I'm not really interested in the outcome at all,
I'm just playing - it's the error that's getting me.
Any thoughts...
p.s. You should find the script above works on your pc...
it's when you scale the array size up that it hits problems.
Flawless---=| If you're going to buy a pet - get a Shetland Giraffe |=---
-
Nov 18, 2002, 06:51 #2
- Join Date
- Feb 2002
- Location
- Gatwick, UK
- Posts
- 1,206
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Save it for the Judge, Momma; Coz this baby's on FIRE!
Sorry
Just excited about the solution.
Well - i suddenly figured - If I'm expecting stabArr
to be iterative and to repass it's stack call - why *shouldn't* I be expecting addCell to do the same!?
Obviously it DOES - so if you seperate it - by putting it
in a timeout - then it won't have that problem.
http://www.thermeoneurope.com/colors.html
Now - if anyone can suggest a way of seperating the ownership WITHOUT putting it in a timeout - be my guest!
Cheers
Flawless---=| If you're going to buy a pet - get a Shetland Giraffe |=---
-
Nov 18, 2002, 09:14 #3
- Join Date
- Feb 2002
- Location
- Gatwick, UK
- Posts
- 1,206
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
A bit more fluff
http://www.thermeoneurope.com/jx.html
Still playing - but whatcha think of it so far?
( Eric shouts "awful" )
Flawless---=| If you're going to buy a pet - get a Shetland Giraffe |=---
Bookmarks