fixes #4519 Cannot set image to null on existing contents

Fixed the issue and pushed code for review, please check it.