Thursday, May 29, 2014

Why would Copying a Large Image to the Clipboard Freeze a Computer?

why-would-copying-a-large-image-to-the-clipboard-freeze-a-computer-00


Sometimes, something really odd happens when using our computers that makes no sense at all…such as copying a simple image to the clipboard and the computer freezing up because of it. An image is an image, right? Today’s SuperUser post has the answer to a puzzled reader’s dilemna.


Today’s Question & Answer session comes to us courtesy of SuperUser—a subdivision of Stack Exchange, a community-driven grouping of Q&A web sites.


Original image courtesy of Wikimedia.


The Question


SuperUser reader Joban Dhillon wants to know why copying an image to the clipboard on his computer freezes it up:



I was messing around with some height map images and found this one:


(http://ift.tt/1jxLB4h)


why-would-copying-a-large-image-to-the-clipboard-freeze-a-computer-01


The image is 21,600*10,800 pixels in size. When I right click and select “Copy Image” in my browser (I am using Google Chrome), it slows down my computer until it freezes. After that I must restart. I am curious about why this happens. I presume it is the size of the image, although it is only about 6 MB when saved to my computer. I am also using Windows 8.1



Why would a simple image freeze Joban’s computer up after copying it to the clipboard?


The Answer


SuperUser contributor Mokubai has the answer for us:



“Copy Image” is copying the raw image data, rather than the image file itself, to your clipboard.


The raw image data will be 21,600 x 10,800 x 3 (24 bit image) = 699,840,000 bytes of data. That is approximately 700 MB of data your browser is trying to copy to the clipboard.


JPEG compresses the raw data using a lossy algorithm and can get pretty good compression. Hence the compressed file is only 6 MB.


The reason it makes your computer slow is that it is probably filling your memory up with at least the 700 MB of image data that your browser is using to show you the image, another 700 MB (along with whatever overhead the clipboard incurs) to store it on the clipboard, and a not insignificant amount of processing power to convert the image into a format that can be stored on the clipboard.


Chances are that if you have less than 4 GB of physical RAM, then those copies of the image data are forcing your computer to page memory out to the swap file in an attempt to fulfil both memory demands at the same time. This will cause programs and disk access to be sluggish as they use the disk and try to use the data that may have just been paged out.


In short: Do not use the clipboard for huge images unless you have a lot of memory and a bit of time to spare.


Like pretty graphs? This is what happens when I load that image in Google Chrome, then copy it to the clipboard on my machine with 12 GB of RAM:


why-would-copying-a-large-image-to-the-clipboard-freeze-a-computer-02


It starts off at the lower point using 2.8 GB of RAM, loading the image punches it up to 3.6 GB (approximately the 700 MB), then copying it to the clipboard spikes way up there at 6.3 GB of RAM before settling back down at the 4.5-ish you would expect to see for a program and two copies of a rather large image.


That is a whopping 3.7 GB of image data being worked on at the peak, which is probably the initial image, a reserved quantity for the clipboard, and perhaps a couple of conversion buffers. That is enough to bring any machine with less than 8 GB of RAM to its knees.


Strangely, doing the same thing in Firefox just copies the image file rather than the image data (without the scary memory surge).





Have something to add to the explanation? Sound off in the comments. Want to read more answers from other tech-savvy Stack Exchange users? Check out the full discussion thread here.


















No comments:

Post a Comment