Fixed some memory leaks.
Fixed samples not properly being shutdown when window is killed on Linux.