fixing image memory leak issue