.dispose or .destroy?

Hello,

I’ve really enjoyed my experience with OpenFl so far, but one thing has been giving me a major problem lately. I appear to have a memory leak in my program, as the memory keeps going up until lag eventually consumes it completely. I’ve read up on the topic that you need to remove all event listeners and set the object to null in order for it to be garbage collected, yet I’ve done all of this and my memory usage continues to go up. In HaxeFlixel, I’ve noticed that there is a .destroy() function on sprites and such, and I would use that with OpenFl, but porting my project from pure OpenFl to that has eaten up a lot of time and I still cannot seem to make it work. Does something like this exist in pure OpenFl? I’ve looked all around Google and only found a few answers that seem to say the same thing (Remove event listeners, set to null, etc.) and none of them work. Any help would be very much appreciated!

Make sure you have absolutely no copy anywhere, you need to null them all for the garbage collector to free the memory.

Most likely HaxeFlixel has a destroy function to remove its own cache copy, not a magic function.

Hi ibilon!

In my program, I declar a variable inside a function and push it to am array. After a series of if statements, I removeChild the variable, remove all event listeners associated with it, set it to null (Like: Enemy1List[Enemy1Index] = null;), then slice it from the array. This should be enough to remove it, right? Or am I doing something wrong?

Be aware that if you’re loading assets (like PNG/JPG images) these may be cached, so if your objects do not share assets, you may need to remove them from the cache in order for it to be garbage collected

Ah! Ok! I’ll look into this!

I really like OpenFl, and I’m glad it has such an awesome and friendly community!

Thanks and sorry for late reply :smile: