fix the resource leaking problem by register the images.