I wonder if anyone else ever suffers from this? It’s not something I’ve ever really noticed before, but today I came up with a solution to a problem that has been bothering me for months. The solution was incredibly simple and while the code has changed significantly in functionality it only really took ~50 lines of code to do.
Flash can use a lot of memory, but FMud has always seemed very inefficient. I had put this down to the string handling and the garbage collection and had accepted it as perhaps “just the way it works”. Unfortunately it means that after an hour or so of use FMud can take up so much memory that it causes slowdown on some systems. I didn’t think this was too crippling as I’d always seen FMud as a gateway client; something to put on a website as a quick and accessible way to try out a game. However, these issues had put me off developing it further as a fully fledged game client.
Essentially the FMud display works by reading data from a socket and appending it to a text control using the htmlText property. The data from the socket is parsed for colour codes and they are replaced with appropriate html tags. Unfortunately as more data is appended and the display grows the memory use climbs as well.
I had tried everything I could think of including limiting the size of the display buffer, rewriting the string handling and even destroying and recreating the display window, all to no avail. It seems that the text control is never marked for garbage collection while the application is running, so regardless of what you do with the text every byte received by the client is retained in memory.
The solution was so simple I am not sure how it had eluded me for so long. I had focused all my efforts on trying to improve the performance of appending text to a control whereas what it needed was a different approach altogether.
Instead of appending data from the server to a text control, FMud now buffers data from the server creating a new text control for each line which is then added to a display container. This way each line exists as a discrete object so once it is removed from the display the memory is recycled by the garbage collector. So far this approach appears to have dramatically reduced memory usage.

Congrats on working this out, this will help your product become much more usable by the general public, this might just yet become the tool that crosses the barrier and gets non text gamers into muds.
LikeLike