I am not sure why it has worked exactly though. The memory used and free values do not change at all now which is fantastic as it means every page impression leaves the system in the same state regarding memory usage which is brilliant news. Here is the solution:
http_server_loop(S, Callback) :-
socket_accept(S, _Client, In, Out),
logger_info("Accepted connection: ~w", [_Client]),
Handler =.. [Callback, Out, Request],
!, %%% <==== here is the fix!
I was going to colour it green but is it a green cut or a red cut? Either way it's bloody magic!! :)
I can take it out and put it back now and try to understand the full enormity of what I have done! LMAO I am guessing that the cut has caused all variables currently bound with values to be discarded or something like that.