Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8091583

Add API to get an approximate heap size of Image objects


    • Type: Enhancement
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 7u6
    • Fix Version/s: tbd
    • Component/s: javafx
    • Labels:
    • Environment:



      My program is very image heavy, so heavy in fact that it can blow through 200 MB of heap space in less than a second. To keep a handle on this a cache is implemented to keep frequently used images in memory and discard ones that are no longer used.

      The cache implementation would benefit greatly from having some knowledge of the (decoded) size of these image in judging the amount of heap space that is occupied by Images, and also in deciding which Image is best discarded first. A simple method like getDecodedSize() or getHeapSize() which returns an approximation of the amount of heap space the Image is taking up would be great.

      Alternatively, it would be possible to add API that more accurately describe the Image and its decoded form. With the PixelReader and PixelFormat.Type + height/width information one can get a close approximation, but it assumes a lot about the internal structure of Image. For example, one could assume that a 1000x1000 image with 32-bit PixelFormat takes up roughly 4 MB of space. The PixelFormat.Type does not provide any "bytesPerPixel" value, but one can guess them for each type -- guessing is however not really future proof and can be wayoff if at some point Images are supported that use 16 bits per channel.

      As a second alternative, add API for caching Images :)

      As a work-around I've implemented a method that does an educated guess on how much heap an Image is consuming.




            • Assignee:
              jhendrikx John Hendrikx
            • Votes:
              0 Vote for this issue
              2 Start watching this issue


              • Created: