What do these SWF Profiler results mean? (Memory Leak problem)

68 views
Skip to first unread message

LangLearn

unread,
Dec 3, 2015, 3:35:26 PM12/3/15
to haxef...@googlegroups.com
I have been trying to fix my memory problems for nearly 2 weeks but I have no idea what is going wrong with the game. I am pretty sure I have checked every class / variable to make sure it gets destroyed properly 5 times at least. Every thing I can use FlxDestroyUtil.destroy on I use that, if I can not do that then I declare the variables like private var damage:Null<Int>=5 then say damage = null in the destroy function.


The playstate loads my overworld tilemap so that is always in the background of the battle system but I disable the map stuff from updating when the battle system is open. The battle system used to be a substate of the playstate but that was not working properly with my complex menu system so I decided to use a FlxGroup for my battle system. For a few days I tried getting the revive system working properly but it had memory issues. Then I just decided to completely open a new playstate after each battle since I think most games switch states after each battle. I thought the memory would be released every time a state is changed but that did not help. I think maybe it made it worse but I am not sure..


The game starts at around 90 to 100 MB memory usage then climbs higher and higher. After one hour the memory usage was at 950 MB but I realized the battle system stopped since I ran out of units. I think it would have been closer to 1200 MB. The battle system is turn based rpg type so there are not 20 bullets being created every second or anything like that. I have 14 units (7 for player and 7 for enemy), 14 health bars, 14 FlxText to display the number of units, a spell bar at the bottom etc. If you have played heroes of might and magic III then it looks pretty much exactly like that except my units never move on a grid and battles last something like 5 seconds.


The first image is what the game looks like after starting it. The second image is after the game runs for around an hour. I am not really sure how to interpret this stuff but things are definitely getting higher. I tried everything I can think of already which is why I tried using this Flash Develop SWF Profiler thing. I do not have windows 7 so I can not use adobe scout.



Jeru Sanders

unread,
Dec 3, 2015, 4:43:48 PM12/3/15
to haxef...@googlegroups.com
There's [hxScout](http://hxscout.com/) as well, you could try that. If you want to send me the swf I can send you a Scout profile.

LangLearn

unread,
Dec 3, 2015, 9:43:07 PM12/3/15
to HaxeFlixel
I tried hxscout but it seems my windows version of the game crashes and I have not leaned how to debug windows yet :/

So I decided to just start from nothing and slowly add in everything one at a time. The first thing I tested was my map, with  flxg.switchstate 100 times it went from 40 MB to 120MB, then I let it stay there for a few minutes but the garbage collection never lowered it a single MB. Then I tried removing a function call that was parsing my town objects from a duplicate local variable tilemap and suddenly the memory leak was gone. After that I just added duplicateMap.destroy(); to the end of the function which fixed that memory leak problem, then realized there is no reason to create a duplicate of the tilemap since I can just use the real one.....

I ran my battle system for 20 minutes and the memory leak is gone, at least from the battle system.

Are FlxObjects (like my duplicate tilemap) created locally supposed to ignore garbage collection when a function ends / when state changes / if they are not even added? I am sure I have created more local function flxobjects without adding/destroying expecting them to instantly be destroyed when a function ends. I guess I should make sure they are getting removed from memory...

Jeru Sanders

unread,
Dec 4, 2015, 5:51:12 PM12/4/15
to HaxeFlixel
That's interesting, I suggest writing an issue to the [github page](https://github.com/HaxeFlixel/flixel). As that's probably not a thing anyone here can just rattle off the answer to.
Reply all
Reply to author
Forward
0 new messages