Fixed an issue that caused memory leaks.