Move the processing of the documents out of the daemon. Make it a separate script, that you call from the daemon. That probably should fix most problems... And if it doesn't, you've got a lot smaller problem space to dig into.
yes remember, garbage collection only comes in to play
when an object goes out of scope or has no references.
so if you have a global array say where you push data
then it will never be released.