Nifty Memory Leak


#1

So I have been wracking my brain trying to find out why Spoxel tends to start lagging about after an hour of gameplay. After a lucky break, a user noticed the spike in cpu usage that increased significantly over time in a section of code that adds and removes nifty elements. As it turns out, every element that nifty creates it calls:

nifty.getEventService().subscribeStrongly("style-refresh:" + getStyle(), styleListener);

When nifty removes elements… well it doesn’t remove them from this event service. Also, every time you add an element it calls this method which iterates through every element in the list that matches the key. As far as I can tell that subscription isn’t used under normal operation (I removed it in my local copy of nifty and have had 0 issues so far). I’m not sure why they set this up since it is far cheaper to just walk the nifty scene graph and check for styles to update. Instead you get to pay a performance penalty any time an object is added or removed as well as never freeing any of the memory since it’s never removed from those internal lists.

If I wasn’t so close to release I probably would switch away from nifty at this point.


#2

Please open an issue:

https://github.com/nifty-gui/nifty-gui/issues


#3

I meant to do that earlier but it looks like I forgot to hit submit. It has been added now. I’m not holding my breath since Nifty is basically just in maintenance mode now.


#4

That is true but they seem to be accepting PRs still, quite fast actually.