Fixed the memory leak with model loading