Fix memory usage problem when working with bitmaps.