Issue with Memory Leak


(Joseph DeConto) #1

Hello. I was wondering if someone could help me track down the cause of a memory leak that I have been trying to nail down for the passed week. I have found, I hope, the cause of the leak but I cannot seem to get rid of it. While switching levels I run through an array that contains all the Entities, recycle the Entities. Then I splice the array. The issue I have noticed is that even after splicing the array I can call a trace on the Entities and apparently they are still their, they seem to disappear when I add more items to the array but the memory used for the Entities stays used.

Here is the code I am using to recycle the entities:

for (var index:int = 0; index < worldItems.length; index += 1)
            {
                recycle(worldItems[index]);
            }
            worldItems.splice(0 , worldItems.length);
            loadMap();

Any help would be greatly appreciated!


(Jacob Albano) #2

The memory is still in use because the entities are still being stored. When you recycle, you’re adding your entities to a list to be reused later. If that’s not the behavior you want, use remove instead.


(Joseph DeConto) #3

I just swapped in remove for the recycle and I get the same results. The game adds ~1.4 mb to the memory every time I load a new level, I am not sure that it is the Entities that are causing the leak.


(Jacob Albano) #4

Does the memory normalize after some time? If it’s only a few MB every time you load a level it’s probably not a big deal. The Flash Player will run a garbage collection occasionally and get rid of loose memory.


(Joseph DeConto) #5

It goes down about 0.3 MB after a few second but the problem is that the levels take maybe 10, 20 second to complete. After a few minutes of gameplay the frame rate drops to around 40.