Prevent Unexpected ImageIO Disk WritesRecently I was working on CamViewer, an application to stream live images and audio from a webcam to your desktop. I noticed that the computer I was running it on was constantly accessing the disk. Since this program is intended to run continuously for long periods of time, excessive disk access seemed to be a problem. I double-checked the code and I wasn't creating files directly nor was I using
ImageIO Disk CachingAfter some investigation, I discovered that, by default, ImageIO caches images to disk when you read them, even if you are reading them into memory for temporary, throwaway use. Fortuantely the fix is simple, put this in your code before you read an image using ImageIO:
ImageIO.setUseCache(false);This will disable disk caching in the ImageIO library.
This helped CamViewer tremendously. After startup, disk activity goes back to the original level. This should improve battery life on laptops and reduce the load on the drive being used for temporary files.
Copyright © 2016 Andrew Oliver