scrollback optimizations.
fix memory leak.