# Start with a blank image - somehow this causes memory cleanup $TK{'image-'.$NVP{'Id'}}=$TK{'canvas-'.$NVP{'Id'}}->Photo(-file => "" ); # Create an image object for the image file of the correct format $TK{'image-'.$NVP{'Id'}}=$TK{'canvas-'.$NVP{'Id'}}->Photo($NVP{'Id'}, -file => $NVP{'File'}, -format => $image{'extension'}); #### # Create a "catch" for closing the window $TK{'pw-'.$NVP{'Id'}}->protocol('WM_DELETE_WINDOW' => [\&CleanUpOnExit, $NVP{'Id'}]); #### sub CleanUpOnExit { # Get the id my $ID=shift(@_); # Delete images on the canvas $TK{'canvas-' . $ID}->delete("all"); # Delete the original image (delete $TK{'image-' . $ID})->delete(); # Destroy the popup window $TK{'pw-' . $ID}->destroy(); # Exit the Tk window Tk::exit; }