# Flixel text causing memmory leak (FlxText) - AS3

I am calling kill() and destroy() on flxText when i dont need it anymore, how come its still using the memmory it let the game run for a while it went up to 1,5 gig of ram, then i commented it out the code where flxText is made and got this http://shrani.najdi.si/?3u/x6/1MkFPi08/fac.png (using only 170m-190m), so its obviously flixel text not cleaning up propperly , wat do ?

Hi Matthew and thank you for your question.

Since ActionsScript uses garbage collection there are only 2 reasons.

First you have references to these objects in your own objects or from a manager in fixel. In this case be aware to null your references. Maybe the tool mentioned here could be useful.

Second your garbage collection did not trigger automatically. In this case force it to clean up. Sometimes garbage collection can not or need many attempts to free all memory. This is caused by circular references. I.e. A references B and B references A and you null the reference to A.

So what to do. Check if you really null your references and that no reference is left from your side of code. If the problem continuous check if flixel tracks some references internally and lookup how to remove them. If the problem is not solved check for objects that reference each other. Normally this should not cause this problem because garbage collection checks for circular references.

• I make a variabile text via function like this pastebin.com/A0U67d8F , will each var text refrence still exist and point to the new Text that i made even after function ends ? – Matthew Nov 28 '13 at 14:52
• No the reference to the new object is just on the stack and deleted with the end of your method. Anyway if you call this to often in reputation this can cause a huge amount of memory used. You shall initialize your content ones and change its properties not create every time a new one. – NjamNjam Nov 28 '13 at 20:11

So what i did to fix this is, i made 10 variabiles in advance and made the code check if there are any dead ones first, and then just revive the dead one. Recycling 10 objects forever fixed the leak

• If you're using something like flashdevelop you can use the profiler next time. – Sidar Nov 30 '13 at 22:35
• FYI: This is caller object pooling. – Vaughan Hilts Dec 18 '13 at 22:27

I've found it helps to set all references for objects to null on destroy.