What does this mean for me? You will always be able to play your favorite games on Kongregate. However, certain site features may suddenly stop working and leave you with a severely degraded experience.
What should I do? We strongly urge all our users to upgrade to modern browsers for a better experience and improved security.
We suggest you install the latest version of one of these browsers:
Kongregate is a community-driven browser games portal with an open platform for all web games.
Get your games in front of thousands of users while monetizing through ads and virtual goods.
Learn more »
I’m new here. so I’ll introduce myself first! I am MarcianoSR and I love to program, especially with as3. I’m coming here to ask a serious question about optimizing the peformance in such a game, created in as3.
Ive got peformance problems when the game progresses. The game generates objects every certain time, when the game progresses, it will generate objects faster and faster. I think I cannot re-use the objects, but I remove all objects when I dont need them anymore, dispose bitmaps and remove event listeners. Still it lags more and more. What can I do to make it not lag? Is there a way to remove objects entirely?
Thanks for reading,
Make sure you’re (i) removing them from any storage that you put them into (i.e. arrays, vectors or references to them directly from objects); (ii) removing them from the stage, if they’re display objects, and (iii) removing any event listeners that call back to them, as this also counts as a reference and stops the GC collecting them.
Are you experiencing lag spikes at fairly regular intervals? That’s usually the garbage collector, although apparently not always (it has always been the garbage collector _for me_, but I’ve seen people claiming they were not generating any garbage and still had it). Are you experiencing more lag when more objects/effects are on the screen at once? That’s your renderer struggling to keep up with the load. Are you experiencing a general slowdown of the game while your machine starts roaring like a revved-up motorcycle? You might be using so much memory that your computer is caching to disk, which absolutely kills performance.
Try to diagnose exactly what is happening, where and why. FD allows you to monitor your memory usage, see how exactly how many objects of what type are in memory, etc… It’s the ‘SWF profiler’, the little alarm clock icon in the tool bar. I find it a great help to check that I’m not leaking memory or over-generating objects.
Thanks for all the replies.
I found the spot which made all the trouble. It was a single array which I forgot to empty. It got full off objects which I didn’t remove.
Thanks for thinking with me, I really appreciate it.
> *Originally posted by **[UnknownGuardian](/forums/4/topics/294421?page=1#posts-6329332):***
> And if you are running in a loop and are using the method Draco showed, make sure to do `theIndex--;` if you don’t want to skip over the object you just swapped.
Depends on the order of the loop (did you start at the front, or start at the back?). I almost exclusively run through loops back-first these days.
> *Originally posted by **[Draco18s](/forums/4/topics/294421?page=1#posts-6329494):***
> > *Originally posted by **[UnknownGuardian](/forums/4/topics/294421?page=1#posts-6329332):***
> > And if you are running in a loop and are using the method Draco showed, make sure to do `theIndex--;` if you don’t want to skip over the object you just swapped.
> Depends on the order of the loop (did you start at the front, or start at the back?). I almost exclusively run through loops back-first these days.
Running backwards is usually faster (except on older machines) and it prevents skipping over on accident.
A way of recycling would be to include a renew and dispose function. The dispose function ceases everything from being triggered and renders the object invisible or moves it off the stage. The renew function makes the values reset to default as if a new object has been created. Any time you need to create an object you can check if one already exists that is in the disposed state and use that instead. Of course this method has its flaws.