I have written the following plugin from scratch, unfortunately I believe it is causing "Out of memory" exceptions.
Can anyone help me find the leak?
It might have something to do with how I am using the GLOBAL variables:
[Huge chunk of code moderated as per the Forum Rules. Please use the pastebin]