|
-
DOT-INVADER
variables/arrays and RAM
this is a question for you, technicians ^_^
if for example the first frame of my game contains 100 arrays plus numerous of variables... they are stored in the RAM, right? so, the more you have values, the more your RAM will be eaten, and the games/applications will run slower... am i always right?
imagine that case: i have a game that load during the movie a lot of external .swfs... each external .swf have dozen and dozen of arrays and variables to store. when i unload it and load another one, with as many values (named differently i mean), they are not deleted form the RAM i assume...
my question is: is it a good habit to delete elements/values via actionscript from the point that we are not needing them anymore? in my external .swf example, when i unload the movie, is it recommended to delete all it's values...? that are not necessary anymore for the rest of the game, and are reloaded in case we need to load the .swf again?
thanks for your advices, it's just my curiosity...
-
Senior Member
It's a good practice, but it might not be necessary. Graphic manipulation is what really eats up the CPU, not a bunch of vars here and there. Think about what a standard app does variable wise, and you'll see that you can't touch it (even running something uncompiled like a Flash movie).
I have heard that even when you delete variables, they don't leave memory. There might be a garbage collector that goes through. I imagine though that unloading a movie has the deletes the variables much as a "delete" does.
The software I'm currently writing at the company I work for holds a few thousand variables in memory at any one time, and it works fine on a PII 300 (maybe even less).
In other words, don't worry about it.
The future belongs to those who prepare for it today.
-
Untitled-1.fla
In my experience a great number of defined variables does not make the flash movie run slower. It eats some RAM, but that's not an issue on most computers.
Try defining 10000 variables and see if the movie runs slower:
code: for(var n=0;n<10000;n++) {
this["variable_"+n] = Math.random();
}
-
Senior Member
Well I started in flash gaming just about 6 months ago or less, but I've noticed that enterFrames really eat more cpu to a point they can kill the game after a few levels. So you must delete movies you are no longer using (everybody knew that) and avoid enterframes whenever posible, however if you have an array of sorts holding MCs, I cant explain pretty much why, but Ive noticed deleting it after is no longer used, speeds up the game (???).
My guess is, flash may check if there are still pointers to a mc before deleting it (maybe they reference like DX on resources) so deleting the array causes the unused movies to be actually deleted. Im out on a limb here, since I havent found a better explanation though.
-oh btw is true: arrays by themselves dont cause flash to slow down, Ive been working with huge arrays holding XML data (100k-500k) and while it takes quite a while to load, flash didnt even tingle on the framerate department. (I did had to optimize it to keep the load times low though) It seems only a good number of movies (specially with color effects/animations) running may cause flash to bog down on frames.
Btw, is there some way to check how much memory you are using on flash? that might be interesting/useful.
Last edited by AzraelKans; 08-13-2003 at 07:06 PM.
-
Untitled-1.fla
is there some way to check how much memory you are using on flash? that might be interesting/useful
If you run Win NT/2000/XP then you can run the movie in the stand alone player and check the process Mem Usage in Windows Task Manager (Ctrl+Alt+Delete). Look for SAFlashplayer.exe. If I run a very simple movie the player uses about 5Mb. If I run a more complex movie it takes somewhere in the range 20-30Mb.
-
DOT-INVADER
well, thanks a lot for all these infos, guys...
that's right, graphics elements take so much CPU intensive... also take care with your enterFrame events, don't over-abuse them ^_^
> that's an aspect i always work with my games...
anyway, i'm happy to know that deleting useless array / variables / values is not so important...
i asked because my fighting game contains soooo many arrays; each character has a dozen of them (really, several screens of arrays filled), and i want it to be as smooth as possible, even if i'm using these damn slowing down scrollings (fortunately they may be desactivated)...
anyway, i guess that if 2 arrays have the same name, the old one is definitely deleted of the memory and replaced...
-
Senior Member
If you are worried about memory usage, you can actually free up quite a lot of memory just by coding in reasonable way (Im sure those are not news for you).
You can use
var variablename
in the functions which deletes variablename after finishing function.
You can also use variables inside mc's which get deleted when mc is deleted.
You can use delete command to delete stuff you dont need anymore.
Still, I doubt if all your arrays can take as much memory as 1 mp3. When you use sounds in your game, they can take several MB and all they use same memory.
-
Senior Member
the thing that I dioscover, and wich I hope the next flash version has, a clear RAM action.
Why?? well, when I build my Internet Radio Player, it basicly plays streaming audio station, but the thing is that the only way to make it work is to use arrays, the think is that until you don't click on teh "Stop" button, or pause button, the Flash Player is taking more and more RAM, cause it dosen't clear the ram after playing. (man it's hard to explaine espacially when english is your second language)
I think the best way to anderstand it is to see it. (dosen't work in IE)
http://pages.infinit.net/eps/player/radio2.html
(try "groov Salad" station most liklly to work. (1- incase you ask, my radio is not finished. 2- I placed a bleu bar wich is growin, when teh music is playing, as you can realise if it touches teh max, it's most likelly to starting to get slower, click on teh glowing button to reaload teh player (currentlly teh only way to clear teh ram)))
Last edited by asdfghjkl; 08-20-2003 at 10:32 PM.
-
I dont think variables take up much ram anyways
they're just a few bytes
compared the 128+ megs of ram most people have
thats about
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|