Added a guard in IndexController to free memory if it's necessary.