Use of memory rises without explanation


(Linck) #1

I was testing a game that I’m developing and noticed that my memory usage is rising really fast for some reason. Then I decided to create a very basic code to see what can cause the memory usage to rise. Look at this code:

public class MemoryTest extends Engine
{
	public function MemoryTest()
	{
		super(1920, 1080, 60, false);
	}
	
	override public function init():void 
	{
		super.init();
		FP.console.enable();
		FP.console.visible = true;
		FP.screen.smoothing = true;
		FP.world = new MemoryTestWorld();
	}
}




public class MemoryTestWorld extends World
{
	public function MemoryTestWorld()
	{
	}
}

It’s a code that has almost nothing right? I observe the use of memory in the falshpunk debug console itself, and with this code, my memory usage keeps rising, but very very slowly, something like 0.01mb every 30 seconds, but It keeps rising, and never drops.

Can anyone explain me why this is happening.


(azrafe7) #2

@Ultima2876 probably knows what’s going on…

I’d guess it’s just the overhead of updating strings in Console.as (which can’t really be fixed). You can try running in release mode, disable the console and trace System.totalMemory every once in a while to see if it changes something.

For proper profiling you should look into Adobe Scout.


(TaylorAnderson) #3

I made a project with these two files and copy-pasted this code into them, and I’m not seeing the memory rise, so it might be caused by something else on your computer. Memory increases that miniscule probably have a pretty good chance to be random


(Linck) #4

Alright, I’ve tested a little more and It seems that the memory goes back at some point, so It keeps rising up to a certain amount, and then goes back to where It was, and the process repeats itself. This is happening even in my main project, where the memory rises in a much faster pace.

I’d like to know though, why exactly this isn’t happening in your computer @TTL_Anderson, I’m using flash builder here, and I have tested both as an Web Application, and a desktop application using AIR. The same thing happens. I have also tried to make a release, and disabling the console (by not calling “console.enable()”),and leaving just a “net.flashpunk.graphics.Text” showing the “flash.system.System.totalMemory”,as you told me @azrafe7, but the same thing happens.


(Jacob Albano) #5

Memory cycling like you described is perfectly normal for a Flash game. As objects are allocated and abandoned, the amount of memory the garbage collector can free rises. Periodically it will run and clear out a large amount at a time, at which point the process starts again.

Also worth bearing in mind is that the console’s memory display (and the Flash function that it uses to get that value) isn’t entirely accurate.

If you notice a rapid increase in memory usage that never goes down, then you have a problem. Otherwise, don’t worry about it too much.