Googling to try to solve my problem (Memory leaks from custom function 1) I came across this, which is how i was doing it originally which was working haha. Did this answer not take memory leaks into account or has something changed since last year?  Or upon further research was this answer assuming the state was normal variables and not other tensors?